• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting System time  RSS feed

 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a bit confused. I am trying to get the system time to display in a label on one of my applications. I created a GregorianCalendar object, and called method getTime(), but the time it returns is one hour earlier than what my PC clock is displaying.
Can anyone help me understand why?

Thanks!
 
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you create a GregorianCalendar object, are you passing in the time zone? If not, that's probably your error.
 
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jennifer,

Try this:



The default constructor uses the default timezone & locale. So it should returns the same time as your PC clock display.

HTH.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jennifer,

Does your location adjust for Daylight Savings Time? If so, this may be a part of the problem. you should check if the timezone used by your GregorianCalendar object is Standard or Daylight Savings Time.

HTH

Layne
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!