• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Time difference

 
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Art,
Thanks a lot. I will try this first thing tomorrow morning.
Dilip
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic