aspose file tools*
The moose likes Java in General and the fly likes How do I calculate the no.of.days. between two timestamps? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How do I calculate the no.of.days. between two timestamps?" Watch "How do I calculate the no.of.days. between two timestamps?" New topic
Author

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

Mike Jeya
Ranch Hand

Joined: Apr 15, 2004
Posts: 54
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

Joined: Jul 01, 2004
Posts: 108
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I calculate the no.of.days. between two timestamps?
 
Similar Threads
What does timestamp plus 1 mean?
timestamps
change data type from string to timestamp
Timestamp in GMT and the difference
Handling java.sql.Timestamp