File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes typecast gregoriancalendar object as date object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "typecast gregoriancalendar object as date object?" Watch "typecast gregoriancalendar object as date object?" New topic
Author

typecast gregoriancalendar object as date object?

achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
Hi I need to do some simple date calculations, like find out the number of days between two dates e.g.

Obviously I can do this using Date objects.
But I have codes which use GregorianCalendar objects. The long (workable) way is to typecast the GregorianCalendar objects and then parse them back to Date objects for the calculation.
That seems rather cumbersome!
Is there a more elegant way of subtracting (or adding) two GregorianCalendar objects without to get the difference in number of days?
TIA :-)


humanum errare est.
meenakshi ashokkumar
Greenhorn

Joined: Mar 07, 2004
Posts: 22
hi,
check out if this kinda code can be of help!
import java.util.*;
class GregT{
public static void main(String ar[]){
Calendar gcala=new GregorianCalendar(2004,01,17,8,32,30);//Jan 17th 2004
Calendar gcaln=new GregorianCalendar(2004,03,17,8,32,30);//March 17th 2004
int var1=gcala.get(Calendar.DAY_OF_YEAR);
int var2=gcaln.get(Calendar.DAY_OF_YEAR);
System.out.println(var2-var1);

}
}
achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
Thanks for your time and input.
Works out to about the same number of lines of codes ;-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: typecast gregoriancalendar object as date object?
 
Similar Threads
Number of weeks between two dates
Date Calculation in JAVA - Is it really trivial ?
Gregarion Calendar causing problem when adding dates.....
3 Oct 2010 only has 23 hours?
Bug in Gregorian Calendar?