Java TimeZone Create toTimeZone(int gmtOffset)

Here you can find the source of toTimeZone(int gmtOffset)

Description

Returns a TimeZone object based upon an hour offset from GMT.

License

Apache License

Declaration

public static TimeZone toTimeZone(int gmtOffset) 

Method Source Code

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

import java.util.TimeZone;

public class Main {
    /**/*from   w ww  .  j a  v a2s. c o  m*/
     * Returns a TimeZone object based upon an hour offset from GMT.
     *
     * @see java.util.TimeZone
     */
    public static TimeZone toTimeZone(int gmtOffset) {
        if (gmtOffset > 12 || gmtOffset < -14) {
            throw new IllegalArgumentException("Invalid GMT offset");
        }
        String tzId = gmtOffset > 0 ? "Etc/GMT+" : "Etc/GMT";
        return TimeZone.getTimeZone(tzId + gmtOffset);
    }
}

Related

  1. getTimeZoneMap()
  2. getTimeZoneOfTenant()
  3. getTotalTimeZoneOffset(TimeZone zone)
  4. getUserTimeZoneDate(String userTimezone)
  5. testSimpleTimeZone()
  6. toTimeZone(String value)
  7. toTimeZone(String zone)