Java Calendar Create getCalendar(String yyyy, String mm, String dd)

Here you can find the source of getCalendar(String yyyy, String mm, String dd)

Description

get Calendar

License

Apache License

Declaration

public static Calendar getCalendar(String yyyy, String mm, String dd) 

Method Source Code


//package com.java2s;
/*/*from w w w. j  av a  2  s.  c  o m*/
 * Copyright 2011 Kazuhiro Sera
 *
 * 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;

public class Main {
    public static Calendar getCalendar(String yyyy, String mm, String dd) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, Integer.valueOf(yyyy));
        cal.set(Calendar.MONTH, Integer.valueOf(mm) - 1);
        cal.set(Calendar.DATE, Integer.valueOf(dd));
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal;
    }

    public static Calendar getCalendar(int yyyy, int mm, int dd) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, yyyy);
        cal.set(Calendar.MONTH, mm - 1);
        cal.set(Calendar.DATE, dd);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal;
    }

    public static Calendar getCalendar(String yyyy, String mm, String dd, String hh, String mi, String ss) {
        Calendar cal = getCalendar(yyyy, mm, dd);
        cal.set(Calendar.HOUR_OF_DAY, Integer.valueOf(hh));
        cal.set(Calendar.MINUTE, Integer.valueOf(mi));
        cal.set(Calendar.SECOND, Integer.valueOf(ss));
        return cal;
    }

    public static Calendar getCalendar(int yyyy, int mm, int dd, int hh, int mi, int ss) {
        Calendar cal = getCalendar(yyyy, mm, dd);
        cal.set(Calendar.HOUR_OF_DAY, hh);
        cal.set(Calendar.MINUTE, mi);
        cal.set(Calendar.SECOND, ss);
        return cal;
    }

    public static Calendar getCalendar(long timeInMillis) {
        Calendar dest = Calendar.getInstance();
        dest.setTimeInMillis(timeInMillis);
        return dest;
    }
}

Related

  1. getCalendar(String dateStr, int inputYearType, int outputYearType)
  2. getCalendar(String dateString)
  3. getCalendar(String gdate)
  4. getCalendar(String str)
  5. getCalendar(String time, char sep, boolean isStart)
  6. getCalendar(TimeZone timeZone, Locale locale)
  7. getCalendarAtMidnight(Date d)
  8. getCalendarBefore(int i)
  9. getCalendarByName(String timeZone)