wood burning stoves 2.0*
The moose likes Java in General and the fly likes Time difference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Time difference" Watch "Time difference" New topic
Author

Time difference

Dilip kumar
Ranch Hand

Joined: Oct 16, 2000
Posts: 360
Hi,
I'm having trouble in getting time difference. Any ideas ?

Hashtable ht = new Hashtable();
public void method1(int record) {
  Date date1 = new Date();
  SimpleDateFormat sdf1 = new SimpleDateFormat( "MM/dd/yyyy hh:mm:ss" );
  ht.put(new Integer(record), sdf1.format(date1).toString());
}
public void method2(int record) {
  Date date2 = new Date();
  SimpleDateFormat sdf2 = new SimpleDateFormat( "MM/dd/yyyy hh:mm:ss" );
  String currentDateTime = sdf2.format(date2).toString();
  String recordLockedDateTime = lockedRecords.get(new Integer(record));
// How to compare time difference between currentDateTime and recordLockedDateTime ?
}
Thanks in advance.
Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
Dilipkumar:
See the bottom of the page--question #37--at this Java FAQ.
Art
Dilip kumar
Ranch Hand

Joined: Oct 16, 2000
Posts: 360
Thanks Art.
But my problem is I'm having date and time in String object.
Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
OK.
Try this:

If you don't want to work in milliseconds, you can manipulate the Date objects that parse() returns instead of working with getTime().
Good luck.
Art
Dilip kumar
Ranch Hand

Joined: Oct 16, 2000
Posts: 360
Art,
Thanks a lot. I will try this first thing tomorrow morning.
Dilip
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Time difference
 
Similar Threads
how to convert date to a string
SimpleDateFormat and locale
Timezone offset to Timezone ID conversion
Comparing two date inputs
Help for using Java Time