File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Timestamp Time Difference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Timestamp Time Difference" Watch "Timestamp Time Difference" New topic
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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14338
    
  22

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 8 API documentation
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Timestamp Time Difference