Java TimeZone Get getFilteredTimeZoneMap()

Here you can find the source of getFilteredTimeZoneMap()

Description

Get time zones.

License

Apache License

Return

map typezone id and GMT

Declaration

public static Map<String, String> getFilteredTimeZoneMap() 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TimeZone;

public class Main {
    private static final int CONSTANT_60 = 60;
    private static final int CONSTANT_1000 = 1000;
    private static Map<String, String> timezoneIDMap;

    /**//from   www  .j a va2  s . c o  m
     * Get time zones.
     * 
     * @return map typezone id and GMT
     */
    public static Map<String, String> getFilteredTimeZoneMap() {
        if (timezoneIDMap == null) {
            timezoneIDMap = new LinkedHashMap<String, String>();
            String[] ids = TimeZone.getAvailableIDs();
            for (String id : ids) {
                TimeZone zone = TimeZone.getTimeZone(id);
                int offset = zone.getRawOffset();
                int offsetSecond = offset / CONSTANT_1000;
                int hour = offsetSecond / (CONSTANT_60 * CONSTANT_60);
                int minutes = (offsetSecond % (CONSTANT_60 * CONSTANT_60)) / CONSTANT_60;
                timezoneIDMap.put(TimeZone.getTimeZone(id).getDisplayName(),
                        String.format("(GMT%+d:%02d) %s", hour, minutes, id));
            }
        }
        return timezoneIDMap;
    }
}

Related

  1. getDiffTimeZoneRawOffset(String timeZoneId)
  2. getDisplayDate(Date date, TimeZone tz, Locale inLocale, int style, boolean includeTime)
  3. getDSTSavings(TimeZone tz)
  4. getDSTTime(TimeZone tz, Date date)
  5. getEnd(String date, TimeZone tz)
  6. getHostDefaultValues()
  7. getHourPart(TimeZone timeZone)
  8. getJapanTimeZone()
  9. getMediumDisplayDate(Date moment, TimeZone tz, Locale inLocale)