Results 1 to 2 of 2
- 06-01-2012, 10:49 PM #1
Member
- Join Date
- Jun 2012
- Posts
- 1
- Rep Power
- 0
calculating number of days between 2 dates chosen in jdateChooser
I have this problem where i cannot figure out a way to calculate the number of days between 2 dates that the user chooses using a jDateChooser ( in netbeans)... so i need help please ... what is the function or stack of commands to realise that ?
- 06-02-2012, 04:57 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: calculating number of days between 2 dates chosen in jdateChooser
You can extract the long values that represent the values of those dates. This give you date information in milliseconds. Subtract the first date with the second will give you the different in milliseconds. To get the values in days you need to divide the milliseconds value with (24 * 60 * 60 * 1000).
Another way is to use the Joda Time, and it will be much simpler, the snippet look like this.
Java Code:import org.joda.time.DateMidnight; import org.joda.time.Days; ... DateMidnight start = new DateMidnight("2010-02-01"); DateMidnight end = new DateMidnight("2012-02-07"); int days = Days.daysBetween(start, end).getDays(); ...Website: Learn Java by Examples
Similar Threads
-
number of the days (-) days gone past
By sh4rif in forum New To JavaReplies: 4Last Post: 05-22-2012, 01:17 PM -
Best way to find number of days between 2 dates??
By alinaqvi90 in forum Advanced JavaReplies: 18Last Post: 11-22-2010, 08:49 AM -
calculating with dates
By hannes in forum New To JavaReplies: 1Last Post: 01-14-2010, 08:22 PM -
[Very Urgent] Need help calculating difference between two dates
By rustix in forum Advanced JavaReplies: 23Last Post: 02-19-2009, 05:24 AM -
No fo days between two dates
By Java Tip in forum Java TipReplies: 0Last Post: 01-28-2008, 09:06 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks