| 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.
|
Jason's Blog
|
 |
 |
|
|
subject: Date diff function in java
|
|
|