wood burning stoves
The moose likes Java in General and the fly likes Date diff function in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date diff function in java" Watch "Date diff function in java" New topic

Date diff function in java

saahil sinha
Ranch Hand

Joined: Apr 07, 2003
Posts: 68
Hi guys,
I like to know if there is any function in java that will perform the diffrence between 2 dates and return it in the no. of days between the 2 dates.If yes what is the function and its syntax
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
You mean something like this:

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
saahil sinha
Ranch Hand

Joined: Apr 07, 2003
Posts: 68
Ur code did give me some idea so i did some thinkin and this is what i actually coded and wanted.
import java.util.*;
public class test_time
{ public static final long DAY = 24 * 3600 * 1000;
public static void main(String args[])
GregorianCalendar gcl1=new GregorianCalendar(2002,2,29);//entry date
GregorianCalendar gcl2=new GregorianCalendar();//return date
public static void daysBetweenDates(GregorianCalendar d1,GregorianCalendar d2)
Date day1=d1.getTime();
long dd1=day1.getTime();
Date day2=d2.getTime();
long dd2= day2.getTime();
int de=(int)((dd1-dd2)/DAY);
Anyways thanx a lot
Jason Menard

Joined: Nov 09, 2000
Posts: 6450
Check out this topic.
I agree. Here's the link: http://aspose.com/file-tools
subject: Date diff function in java
It's not a secret anymore!