Results 1 to 2 of 2
  1. #1
    zahidawi is offline Member
    Join Date
    Jun 2012
    Posts
    1
    Rep Power
    0

    Default 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 ?

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default 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();
    ...

Similar Threads

  1. number of the days (-) days gone past
    By sh4rif in forum New To Java
    Replies: 4
    Last Post: 05-22-2012, 02:17 PM
  2. Best way to find number of days between 2 dates??
    By alinaqvi90 in forum Advanced Java
    Replies: 18
    Last Post: 11-22-2010, 09:49 AM
  3. calculating with dates
    By hannes in forum New To Java
    Replies: 1
    Last Post: 01-14-2010, 09:22 PM
  4. Replies: 23
    Last Post: 02-19-2009, 06:24 AM
  5. No fo days between two dates
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-28-2008, 10:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •