View Single Post
  #1 (permalink)  
Old 04-14-2008, 01:48 AM
vijay balusamy vijay balusamy is offline
Member
 
Join Date: Apr 2008
Posts: 1
vijay balusamy is on a distinguished road
Difference between current date and anothe date
Hi,
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");
dateDifference();
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.");
}
}
Reply With Quote
Sponsored Links