• 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

How do I calculate the no.of.days. between two timestamps?

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a timestamp which is in the form of String(retrieved from LDAP)
for example :20041118120738Z
I have to find the no.of.days different between this timestamp and currenttimestamp.
if I go for, System.currenttimeMillis() to get CurrentTime, is this locale depenedent??
Can any one assist me?
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can convert your time stamp to a java.util.Date object using the SimpleDateFormat class. Once you have the Date object, you can convert that to the milliseconds representation by calling the getTime() method.

Subtract that from the current time, and you'll have the number of milliseconds between the two time stamps. This is easily converted to days.

As for the locale question - System.currentTimeMillis() will return whatever time is reported by the system clock on the machine where your program is running. So, yes, it is locale dependent - if you run the same program at the same time on two different machines in different time zones, you will get different results.
[ November 29, 2004: Message edited by: Fletcher Estes ]
reply
    Bookmark Topic Watch Topic
  • New Topic