• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Time difference

 
Dilip kumar
Ranch Hand
Posts: 360
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 241
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dilipkumar:
See the bottom of the page--question #37--at this Java FAQ.
Art
 
Dilip kumar
Ranch Hand
Posts: 360
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Art.
But my problem is I'm having date and time in String object.
 
Art Metzer
Ranch Hand
Posts: 241
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 360
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Art,
Thanks a lot. I will try this first thing tomorrow morning.
Dilip
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic