wood burning stoves 2.0*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date diff function in java" Watch "Date diff function in java" New topic
Author

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
Hi,
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
daysBetweenDates(gcl1,gcl2);
}
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);
System.out.println(day1+":"+day2+"::"+de);
}
}
Anyways thanx a lot
Jason Menard
Sheriff

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
 
Similar Threads
Static Main function VS Static user define function
method and function
which string function to remove whitespace between two strings
Date Difference
How do i call my function in JSP