Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2008
    Rep Power

    Default Difference between current date and anothe date

    Please find the code to find the date difference between current date and user specified date is there a better logic rather than this.
    import java.util.Calendar;
    import java.util.Date;

    public class Sample {

    public static void main(String arg[])
    System.out.println("Process Started");
    System.out.println("Process Completed");

    public static void dateDifference()
    Date currentdate = new Date();
    Calendar calUpdated = Calendar.getInstance();
    calUpdated.set(2008, 01, 01);
    long currentDateMilliSec = currentdate.getTime();
    long updateDateMilliSec = calUpdated.getTimeInMillis();
    long diffDays = (currentDateMilliSec - updateDateMilliSec) / (24 * 60 * 60 * 1000);
    System.out.println("Time in days: " + diffDays + " days.");

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Cebu City, Philippines
    Rep Power


    You can do it yourself.

    The most accurate time in long type capturing value is the System.currentTimeMillis() ...... Have an experiment on it....

    You can also use DateFormat.... it is useful. There are deprecated methods in Date that really helps are also in DateFormat class...

    Don't be on a hurry,

Similar Threads

  1. java.util.Date vs java.sql.Date
    By Jack in forum New To Java
    Replies: 5
    Last Post: 10-28-2010, 02:59 PM
  2. Inserting current date into a DB table
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-15-2008, 08:38 AM
  3. Getting current date using dual (Oracle)
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 02-13-2008, 04:46 PM
  4. Date comparison
    By Rageagainst20 in forum New To Java
    Replies: 0
    Last Post: 12-19-2007, 06:34 PM
  5. how to get the current date and time
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 06:05 PM

Posting Permissions

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