• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

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
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic