| Author |
Timestamp Time Difference
|
Mingwei Jiang
Ranch Hand
Joined: Feb 19, 2004
Posts: 63
|
|
Hi, My program runs on one remote unix machine. And I use to get the timestamp. But weird thing is it prints out a very strange value, different from the output using the date command on unix. When issue a date command on bash, it prints: Fri Aug 10 01:51:21 GMT 2007 But java program prints: 2007-08-10 15:51:07.372 My local time is: 2007-08-10 16:51:00 Why java gave me such a strange value which is different from either the remote server time and my local time? Thanks
|
 |
Kail Limas
Greenhorn
Joined: Jul 09, 2007
Posts: 24
|
|
|
look at the toString mehtod. It returns the nanoseconds too.
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12952
|
|
The date command prints the time in GMT. Your Java program prints the time in your local timezone, but probably without taking summertime into account. The ".372" are the milliseconds. Try this to see in which timezone Java prints the time and date: If you want the date and time printed in a specific timezone, you can set the timezone on the DateFormat object. For example:
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Mingwei Jiang
Ranch Hand
Joined: Feb 19, 2004
Posts: 63
|
|
Thank you guys! I got it. Jesper is right. Java printed my local time and took summer time into consideration. Actually my Java program was wrapped into another main program, and it took care of the time thing. That's why I had the confusion. Thanks
|
 |
 |
|
|
subject: Timestamp Time Difference
|
|
|