Java TimeZone Get getPossibleUserTimezoneList(int userOffsetInHours)

Here you can find the source of getPossibleUserTimezoneList(int userOffsetInHours)

Description

Add possible client list from it's current GMT offset in hours We add the xones for the current offest and also the ones for offset-1 and offset+1 because we have no way to know (or at leats that i know of) wether the client is currently in Daylight savings or not by adding the 1hour before and after timezones this should cover the potential offsets at those times of the year where the client is in DST but GMT is not yet.

License

Open Source License

Parameter

Parameter Description
hoursOffset a parameter

Declaration

public static ArrayList getPossibleUserTimezoneList(int userOffsetInHours) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.TimeZone;

public class Main {
    /**//from  w w w  .  ja  va  2s  .co m
     * Add possible client list from it's current GMT offset in hours
     * We add the xones for the current offest and also the ones for offset-1 and offset+1 because
     * we have no way to know (or at leats that i know of) wether the client is currently in Daylight savings or not
     * by adding the 1hour before and after timezones this should cover the potential offsets at those times of the year
     * where the client is in DST but GMT is not yet.
     * Ex: client in the US during late march is -7 vs GMT(not swicthed to summer time yet) rather than usual -8.
     * @param hoursOffset
     * @return
     */
    public static ArrayList getPossibleUserTimezoneList(int userOffsetInHours) {
        ArrayList list = new ArrayList();
        String[] s1 = TimeZone.getAvailableIDs(userOffsetInHours * 3600000);
        for (int i = 0; i != s1.length; i++) {
            list.add(s1[i]);
        }
        s1 = TimeZone.getAvailableIDs((userOffsetInHours - 1) * 3600000);
        for (int i = 0; i != s1.length; i++) {
            list.add(s1[i]);
        }
        s1 = TimeZone.getAvailableIDs((userOffsetInHours + 1) * 3600000);
        for (int i = 0; i != s1.length; i++) {
            list.add(s1[i]);
        }
        return list;
    }
}

Related

  1. getMilitaryTimeZoneCharacter(TimeZone tz)
  2. getMillis(TimeZone tz, int year, int month, int day, int hour, int minute, int second, int millis)
  3. getMoscowCalendar()
  4. getMoscowTimeZone()
  5. getNextHour(final String timezone)
  6. getRawOffset(String timeZoneStr)
  7. getRawOffsetDifference(TimeZone from, TimeZone to)
  8. getServerTimezoneOffset()
  9. getTime(boolean lenient, TimeZone tz, int year, int month, int day, int hour, int minute, int second, boolean setMillis, int nano)