Java Calendar Create getCalendarByName(String timeZone)

Here you can find the source of getCalendarByName(String timeZone)

Description

get Calendar By Name

License

Apache License

Declaration

public static Calendar getCalendarByName(String timeZone) 

Method Source Code

//package com.java2s;
/*//from  www  .ja  va 2s. c o m
 * Copyright (C) 2014 Dell, Inc.
 * 
 * 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.Calendar;

import java.util.TimeZone;

public class Main {
    public static Calendar getCalendarByName(String timeZone) {
        timeZone = timeZone.trim();
        TimeZone zone = TimeZone.getTimeZone(timeZone);
        String id = zone.getID();
        if (id.compareTo(timeZone) != 0) {
            throw new IllegalArgumentException("Bad timezone name: '" + timeZone + "'");
        }
        return Calendar.getInstance(zone);
    }

    public static TimeZone getTimeZone(String timeZone) {
        timeZone = timeZone.trim();
        TimeZone zone = TimeZone.getTimeZone(timeZone);
        String id = zone.getID();
        if (id.compareTo(timeZone) != 0) {
            throw new IllegalArgumentException("Bad timezone name: '" + timeZone + "'");
        }
        return zone;
    }
}

Related

  1. getCalendar(String time, char sep, boolean isStart)
  2. getCalendar(String yyyy, String mm, String dd)
  3. getCalendar(TimeZone timeZone, Locale locale)
  4. getCalendarAtMidnight(Date d)
  5. getCalendarBefore(int i)
  6. getCalendarBySpecific(int year, int month, int date, int hour)
  7. getCalendarByValue(String timeZone)
  8. getCalendarDate()
  9. getCalendarDate(Calendar calendar)