Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Timestamp Time Difference

 
Mingwei Jiang
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
look at the toString mehtod. It returns the nanoseconds too.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Mingwei Jiang
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic