Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Timezone in java?

Options
  • 27-05-2005 2:28pm
    #1
    Closed Accounts Posts: 2,653 ✭✭✭


    Is there a method in java to get the timezone that a computer is in? All I want is a method that checks the system settings and returns an integer, from -12 to +12 for whatever the difference is to GMT. I've been looking at the java Timzeone API but it only seems to support creating timezones based on inputted locations, I want something that just automatically checks what location the computer is in...


Comments

  • Registered Users Posts: 6,508 ✭✭✭daymobrew


    I know shag all Java, but from looking at the online docs maybe the TimeZone class could be useful (TimeZone.getDefault() method).

    Or the Calendar class.
    The Date class had the following note for the getTimezoneOffset() method:
    int getTimezoneOffset()
    Deprecated. As of JDK version 1.1, replaced by -(Calendar.get(Calendar.ZONE_OFFSET) + Calendar.get(Calendar.DST_OFFSET)) / (60 * 1000).
    so maybe ZONE_OFFSET and DST_OFFSET of the Calendar class is what you need.


  • Closed Accounts Posts: 2,653 ✭✭✭steviec


    Yea got it... I just wasnt reading the API properly... timezone.getdefault() does the trick :)


Advertisement