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

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

Description

set Calendar Fields

License

Open Source License

Declaration

private static void setCalendarFields(Calendar cal, int year, int month, int day, int hour, int minute,
            int second, int millis) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    private static void setCalendarFields(Calendar cal, int year, int month, int day, int hour, int minute,
            int second, int millis) {
        if (year <= 0) {
            cal.set(Calendar.ERA, GregorianCalendar.BC);
            cal.set(Calendar.YEAR, 1 - year);
        } else {//w  ww  .  j  av a 2 s.  c  o  m
            cal.set(Calendar.ERA, GregorianCalendar.AD);
            cal.set(Calendar.YEAR, year);
        }
        // january is 0
        cal.set(Calendar.MONTH, month - 1);
        cal.set(Calendar.DAY_OF_MONTH, day);
        cal.set(Calendar.HOUR_OF_DAY, hour);
        cal.set(Calendar.MINUTE, minute);
        cal.set(Calendar.SECOND, second);
        cal.set(Calendar.MILLISECOND, millis);
    }
}

Related

  1. isSameWeekOfYear(Calendar calendar1, Calendar calendar2)
  2. isToThisDayOrLater(int year, int month, int day, java.util.Calendar start, java.util.Calendar end)
  3. isWithinYears(int year, java.util.Calendar start, java.util.Calendar end)
  4. parseCalendar(int year, int month, double day, TimeZone zone)
  5. sameYear(Calendar one, Calendar two)
  6. setDate(Calendar cal, int year, int month, int day)
  7. toCalendar(int year, int month, int day, int hour, int minutes, int seconds)
  8. toStringYearMonth(Calendar calendar)
  9. truncCalendarToHalfYear(Calendar c)