Java TimeZone Create getTimeZone(String id)

Here you can find the source of getTimeZone(String id)

Description

This method performs the task analogous to TimeZone.getTimeZone(), but will return null on failure (rather than GMT).

License

Open Source License

Declaration

public static TimeZone getTimeZone(String id) 

Method Source Code

//package com.java2s;
// modify it under the terms of the GNU General Public License

import java.util.TimeZone;

public class Main {
    /**// w  w  w . j  a  va2  s  . c o  m
     * This method performs the task analogous to TimeZone.getTimeZone(), but
     * will return null on failure (rather than GMT).
     */
    public static TimeZone getTimeZone(String id) {
        // if no ID was provided, return null.
        if (id == null || id.length() == 0)
            return null;

        // look up the associated time zone. Note that if the timezone
        // ID was not recognized, this call will return the GMT time zone.
        TimeZone result = TimeZone.getTimeZone(id);

        // if we got GMT back from the getTimeZone call, but our
        // original timezone ID did not specify GMT, then we should
        // interpret this as an ID lookup failure.
        if ("GMT".equals(result.getID()) && !"GMT".equals(id))
            return null;

        return result;
    }
}

Related

  1. getTimeZone(Date date)
  2. getTimeZone(final Calendar cal)
  3. getTimeZone(final String id)
  4. getTimeZone(final String tzId)
  5. getTimeZone(int rawoffset)
  6. getTimeZone(String idParam)
  7. getTimeZone(String timeZone)
  8. getTimeZone(String timeZone)
  9. getTimeZone(String timeZoneId)