java examples
Home Java Examples Resources Java Interview Questions
Brainpower SEO

How to get timezone ids by their milliseconds offset?

package com.javacoderanch.example.util;

import java.util.TimeZone;

public class TimezoneByOffset {
    public static void main(String[] args) {
        //
        // Gets the available IDs according to the given time zone
        // offset in milliseconds.
        //
        int offset = 8 * 60 * 60 * 1000;
        String[] timezones = TimeZone.getAvailableIDs(offset);

        System.out.println("List of available IDs for GMT:+08:00");
        System.out.println("====================================");
        for (String id : timezones) {
            System.out.println(id);
        }
    }
}

Here are the timezone ids in the GMT+8 offset:

List of available IDs for GMT:+08:00
====================================
Asia/Brunei
Asia/Choibalsan
Asia/Chongqing
Asia/Chungking
Asia/Harbin
Asia/Hong_Kong
Asia/Irkutsk
Asia/Kashgar
Asia/Kuala_Lumpur
Asia/Kuching
Asia/Macao
Asia/Macau
Asia/Makassar
Asia/Manila
Asia/Shanghai
Asia/Singapore
Asia/Taipei
Asia/Ujung_Pandang
Asia/Ulaanbaatar
Asia/Ulan_Bator
Asia/Urumqi
Australia/Perth
Australia/West
CTT
Etc/GMT-8
Hongkong
PRC
Singapore