Java TimeZone To 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;
/**/*www .  j  av a  2 s .com*/
 * Copyright 2004-2005 jManage.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.*;

public class Main {
    /**
     * Parse the given {@code timeZoneString} value into a {@link TimeZone}.
     * @param timeZoneString the time zone 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. createTimeZoneFromDouble(double timeZoneOffsetInHours)
  2. extractTimeZone(String strdate, Date thedate)
  3. setTimeZone(String name)
  4. timeZoneToCode(TimeZone tz)
  5. timeZoneToString(TimeZone tz)
  6. toLocalTZ(Date time, TimeZone localTimeZone)