Java TimeZone String Parse parseTimeZoneString(String timeZoneString)

Here you can find the source of parseTimeZoneString(String timeZoneString)

Description

Parse the given timeZoneString value into a TimeZone .

License

Apache License

Parameter

Parameter Description
timeZoneString the time zone String , following TimeZone#getTimeZone(String) but throwing IllegalArgumentException in case of an invalid time zone specification

Exception

Parameter Description
IllegalArgumentException in case of an invalid time zone specification

Return

a corresponding instance

Declaration

public static TimeZone parseTimeZoneString(String timeZoneString) 

Method Source Code

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

import java.util.TimeZone;

public class Main {
    /**//from   w w w .ja v  a  2 s. co m
     * Parse the given {@code timeZoneString} value into a {@link TimeZone}.
     * @param timeZoneString the time zone {@code String}, following {@link TimeZone#getTimeZone(String)}
     * but throwing {@link IllegalArgumentException} in case of an invalid time zone specification
     * @return a corresponding {@link TimeZone} instance
     * @throws IllegalArgumentException in case of an invalid time zone specification
     */
    public static TimeZone parseTimeZoneString(String timeZoneString) {
        TimeZone timeZone = TimeZone.getTimeZone(timeZoneString);
        if ("GMT".equals(timeZone.getID()) && !timeZoneString.startsWith("GMT")) {
            // We don't want that GMT fallback...
            throw new IllegalArgumentException("Invalid time zone specification '" + timeZoneString + "'");
        }
        return timeZone;
    }
}

Related

  1. guessTimeZone(String timezoneOffset)
  2. parseCal(long time, TimeZone to)
  3. parseDA(TimeZone tz, String s)
  4. parseTimeZoneId(String timeZoneId)
  5. parseTimeZoneString(String timeZoneString)
  6. safeTimeZone(String s)