Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Timezone in java?

  • 27-05-2005 02: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, Registered Users 2 Posts: 6,677 ✭✭✭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