aspose file tools*
The moose likes Beginning Java and the fly likes Help reg. Days & Dates... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help reg. Days & Dates..." Watch "Help reg. Days & Dates..." New topic

Help reg. Days & Dates...

Jack Daniel
Ranch Hand

Joined: Jun 15, 2002
Posts: 163
Hey e'body,...
It would be Great if anybody can help me with, how I can find the number of Days between two dates..
like for example # days between 08/07/2003 & 09/15/2003 ..
Which Class do you suggest me to Use.. ( Date,Calendar,DateFormat ??? how?)
Thx a lot for your help.. Appreciate it..
Chris Stehno
Ranch Hand

Joined: Feb 26, 2001
Posts: 180
The way I usually do something like that is...
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Date d1 = dateFormat.parse("08/07/2003");
Date d2 = dateFormat.parse("09/15/2003");
long time = d2.getTime() - d1.getTime(); // t dif in ms
// then convert time to the time units you want

- Chris Stehno, SCPJ
Jack Daniel
Ranch Hand

Joined: Jun 15, 2002
Posts: 163
Thanks a lot Chris..
So If you want me to get the # of days ...
I think i'll Go this way :
long time = d2.getTime() - d1.getTime(); // t dif in ms
int days=(int)time/(24*36*100000);
I hope this is going to work always..
Let me know, if by chance i'm going wrong somewhere..
Thx anyway
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Help reg. Days & Dates...
Similar Threads
days between dates
Subtracting Dates in JAVA
Calculating no. of working days between tow dates
How to get the difference between 2 dates ?
Extracting months from Date object data