Java Calendar Create getCalendar(int year, int month, int day, int hours, int minutes, int seconds, TimeZone tz)

Here you can find the source of getCalendar(int year, int month, int day, int hours, int minutes, int seconds, TimeZone tz)

Description

Gets a Calendar object with a specific timezone

License

Open Source License

Declaration

public static GregorianCalendar getCalendar(int year, int month,
        int day, int hours, int minutes, int seconds, TimeZone tz) 

Method Source Code

//package com.java2s;
/*/*from   ww w .j av a2 s. c  o m*/
 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Florent Guillaume
 */

import java.util.Calendar;
import java.util.GregorianCalendar;

import java.util.TimeZone;

public class Main {
    /**
     * Gets a Calendar object.
     */
    public static GregorianCalendar getCalendar(int year, int month,
            int day, int hours, int minutes, int seconds) {
        TimeZone tz = TimeZone.getTimeZone("GMT-02:00"); // in the Atlantic
        return getCalendar(year, month, day, hours, minutes, seconds, tz);
    }

    /**
     * Gets a Calendar object with a specific timezone
     */
    public static GregorianCalendar getCalendar(int year, int month,
            int day, int hours, int minutes, int seconds, TimeZone tz) {
        GregorianCalendar cal = (GregorianCalendar) Calendar
                .getInstance(tz);
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month - 1); // 0-based
        cal.set(Calendar.DAY_OF_MONTH, day);
        cal.set(Calendar.HOUR_OF_DAY, hours);
        cal.set(Calendar.MINUTE, minutes);
        cal.set(Calendar.SECOND, seconds);
        cal.set(Calendar.MILLISECOND, 0);
        return cal;
    }
}

Related

  1. getCalendar(int year, int month, int date)
  2. getCalendar(int year, int month, int day)
  3. getCalendar(int year, int month, int day)
  4. getCalendar(int year, int month, int day, int hour, int min, int sec, String timezone)
  5. getCalendar(int year, int month, int day, int hour, int mins, int secs)
  6. getCalendar(int year, int month, int day, TimeZone timeZone)
  7. getCalendar(long millis)
  8. getCalendar(long millis)
  9. getCalendar(long time)