This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • 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
 
You’ll find me in my office. I’ll probably be drinking. And reading this tiny ad.
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!