Results 1 to 2 of 2
- 04-14-2008, 12:48 AM #1
Member
- Join Date
- Apr 2008
- Posts
- 1
- Rep Power
- 0
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.");
}
}
- 04-16-2008, 04:15 PM #2
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,
sukatoa
Similar Threads
-
java.util.Date vs java.sql.Date
By Jack in forum New To JavaReplies: 5Last Post: 10-28-2010, 02:59 PM -
Inserting current date into a DB table
By Java Tip in forum Java TipReplies: 0Last Post: 02-15-2008, 08:38 AM -
Getting current date using dual (Oracle)
By Java Tip in forum Java TipReplies: 1Last Post: 02-13-2008, 04:46 PM -
Date comparison
By Rageagainst20 in forum New To JavaReplies: 0Last Post: 12-19-2007, 06:34 PM -
how to get the current date and time
By valery in forum New To JavaReplies: 1Last Post: 08-03-2007, 06:05 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks