jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting System time" Watch "Getting System time" New topic

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?

Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 805
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.


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

Joined: Dec 06, 2001
Posts: 3061

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.



Java API Documentation
The Java Tutorial
I agree. Here's the link: http://aspose.com/file-tools
subject: Getting System time
It's not a secret anymore!