• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Timestamp Time Difference

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
look at the toString mehtod. It returns the nanoseconds too.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Beauty is in the eye of the tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic