• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Time printing out ahead of time

 
Ranch Hand
Posts: 185
Netbeans IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

when I run the following program the time returns an hour ahead of time even though the time in my taskbar is correct. The timezone in windows is also set correctly. Does anyone have any ideas why this could be happening?


 
Saloon Keeper
Posts: 14094
319
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't print a Date directly. Instead, you should create a SimpleDateFormat with the desired format and locale, and then use System.out.println(formatter.format(date)).
 
Alan Smith
Ranch Hand
Posts: 185
Netbeans IDE Firefox Browser Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Don't print a Date directly. Instead, you should create a SimpleDateFormat with the desired format and locale, and then use System.out.println(formatter.format(date)).



Thats not the issue, the toString method prints the time and date out anyway. I am using eclipse and managed a workaround by adding a timezone variable to the eclipse.ini file. Thanks anyways.
 
Ranch Hand
Posts: 36
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the full output you get? is the time zone there? maybe the default time zone of java is different than your local?

also use this new java.util.Date() //print it

Do you get the same output?

---

just saw your answer to eclipse had a different default time zone?

you could test by calling your program from the command line. then you would know if the issue is with the java install
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic