Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-14-2008, 01:48 AM
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.");
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-16-2008, 05:15 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 508
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting current date into a DB table Java Tip Java Tips 0 02-15-2008 09:38 AM
Getting current date using dual (Oracle) Java Tip Java Tips 1 02-13-2008 05:46 PM
Date comparison Rageagainst20 New To Java 0 12-19-2007 07:34 PM
how to get the current date and time valery New To Java 1 08-03-2007 07:05 PM
java.util.Date vs java.sql.Date Jack New To Java 1 07-09-2007 04:22 AM


All times are GMT +3. The time now is 12:00 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org