Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Getting System time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting System time" Watch "Getting System time" New topic
Author

Getting System time

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
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

Joined: Jul 30, 2003
Posts: 804
When you create a GregorianCalendar object, are you passing in the time zone? If not, that's probably your error.


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
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.


SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting System time
 
Similar Threads
Convert Date from one timezone to another
Urgent ... Please help me ...
Actual PC Time
Date issue
JVM