Java Calendar Year calendarOf(int year, int month, int day, int hour, int minute, int second, int millis)

Here you can find the source of calendarOf(int year, int month, int day, int hour, int minute, int second, int millis)

Description

calendar Of

Declaration

public static Calendar calendarOf(int year, int month, int day, int hour, int minute, int second, int millis) 

Method Source Code


//package com.java2s;
import java.util.Calendar;

public class Main {

    public static Calendar calendarOf(int year, int month, int day, int hour, int minute, int second, int millis) {
        Calendar calendar = calendarTodayOf(hour, minute, second, millis);
        return setCalendarDate(calendar, year, month, day);
    }/*from w w w  .  j  a v  a2  s.  c  om*/

    public static Calendar calendarTodayOf(int hour, int minute, int second, int millis) {
        Calendar calendar = Calendar.getInstance();
        return setCalendarTime(calendar, hour, minute, second, millis);
    }

    public static Calendar calendarTodayOf(int hour, int minute, int second) {
        return calendarTodayOf(hour, minute, second, 0);
    }

    public static Calendar calendarTodayOf(int hour, int minute) {
        return calendarTodayOf(hour, minute, 0, 0);
    }

    public static Calendar setCalendarDate(Calendar calendar, int year, int month, int day) {
        calendar.set(Calendar.YEAR, year);
        //Calendar.JANUARY + month - 1 == month - 1
        calendar.set(Calendar.MONTH, month - 1);
        calendar.set(Calendar.DAY_OF_MONTH, day);
        return calendar;
    }

    public static Calendar setCalendarTime(Calendar calendar, int hour, int minute, int second, int millis) {
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minute);
        calendar.set(Calendar.SECOND, second);
        calendar.set(Calendar.MILLISECOND, millis);
        return calendar;
    }
}

Related

  1. calendar(int year, int month, int date, int hourOfDay, int minute)
  2. calendarFor(final int year, final int month, final int day, final int hour, final int minute)
  3. calendarFor(int day, int month, int year)
  4. copyYearMonthDay(Calendar destCal, Calendar sourceCal)
  5. createAndValidateCalendar(int month, int day, int year)
  6. getDecimalYear(Calendar calendar)
  7. getFiscalYear(Calendar calendar)