This week's book giveaway is in the Java 9 forum.
We're giving away four copies of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications and have Sander Mak & Paul Bakker on-line!
See this thread for details.
Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting System time  RSS feed

 
Jennifer Sohl
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!
 
Jeff Bosch
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.
 
Chengwei Lee
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.
 
Layne Lund
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!