Results 1 to 1 of 1
Thread: No fo days between two dates
-
No fo days between two dates
The class below can be used to calculate the no of days between two given dates. Its a very useful script:
Java Code:TestDate(String args[]) { Calendar c1 = new GregorianCalendar();; Calendar c2 = new GregorianCalendar();; // need more error checking here... c1.set(Integer.parseInt(args[0]), Integer.parseInt(args[1]) , Integer.parseInt(args[2]), 0, 0, 0); c2.set(Integer.parseInt(args[3]), Integer.parseInt(args[4]) , Integer.parseInt(args[5]), 0, 0, 0); System.out.println (daysBetween(c1.getTime(),c2.getTime()) + " day(s) between " + args[0] + "-" + args[1] + "-" + args[2] + " and " + args[3] + "-" + args[4] + "-" + args[5]); } static final long ONE_HOUR = 60 * 60 * 1000L; public long daysBetween(Date d1, Date d2){ return ( (d2.getTime() - d1.getTime() + ONE_HOUR) / (ONE_HOUR * 24)); } }
Similar Threads
-
How to Compare two Dates
By Java Tip in forum java.utilReplies: 1Last Post: 06-24-2008, 07:05 AM -
Comparing dates
By Java Tip in forum Java TipReplies: 0Last Post: 01-28-2008, 09:02 AM -
Inbetween Dates
By Rageagainst20 in forum New To JavaReplies: 4Last Post: 12-19-2007, 05:24 AM -
help with dates and time
By osval in forum New To JavaReplies: 3Last Post: 12-12-2007, 12:41 PM -
differences between 2 dates
By cecily in forum New To JavaReplies: 1Last Post: 08-02-2007, 05:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks