This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mike Jeya
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • 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?
 
Fletcher Estes
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic