Java TimeZone Get isValidTimeZoneId(String timeZoneId)

Here you can find the source of isValidTimeZoneId(String timeZoneId)

Description

Checks whether the given time zone id is valid for the other DateFormats used to parse dates in this util class.

License

Open Source License

Parameter

Parameter Description
timeZoneId the time zone id to check

Return

true if the time zone id is valid, false if not

Declaration

public static synchronized boolean isValidTimeZoneId(String timeZoneId) 

Method Source Code

//package com.java2s;
/*//from   w  ww  .j  ava  2  s . c om
 * Copyright (C) 2010 Chair of Artificial Intelligence and Applied Informatics
 * Computer Science VI, University of Wuerzburg
 * 
 * This is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 3 of the License, or (at your option) any
 * later version.
 * 
 * This software is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this software; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
 * site: http://www.fsf.org.
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Locale;

public class Main {
    /**
     * Date format to validate a time zone parsable by the other formats used in this ValueUtils.
     */
    private static final SimpleDateFormat TIME_ZONE_DATE_FORMAT = new SimpleDateFormat(
            "z", Locale.ENGLISH);

    /**
     * Checks whether the given time zone id is valid for the other DateFormats used to parse dates
     * in this util class.
     *
     * @param timeZoneId the time zone id to check
     * @return true if the time zone id is valid, false if not
     */
    public static synchronized boolean isValidTimeZoneId(String timeZoneId) {
        try {
            synchronized (TIME_ZONE_DATE_FORMAT) {
                TIME_ZONE_DATE_FORMAT.parse(timeZoneId);
            }
            return true;
        } catch (ParseException e) {
            return false;
        }
    }
}

Related

  1. getTimeZoneIDs()
  2. getTimeZoneOffset()
  3. getTimeZoneOffset(long t)
  4. getTimezones()
  5. getTimezoneTime(long time, int timezone)