java.util

Class GregorianCalendar

Implemented Interfaces:
Cloneable, Comparable<T>, Serializable

public class GregorianCalendar
extends Calendar

GregorianCalendar is a concrete subclass of Calendar and provides the standard calendar system used by most of the world.

GregorianCalendar is a hybrid calendar that supports both the Julian and Gregorian calendar systems with the support of a single discontinuity, which corresponds by default to the Gregorian date when the Gregorian calendar was instituted (October 15, 1582 in some countries, later in others). The cutover date may be changed by the caller by calling setGregorianChange().

Historically, in those countries which adopted the Gregorian calendar first, October 4, 1582 (Julian) was thus followed by October 15, 1582 (Gregorian). This calendar models this correctly. Before the Gregorian cutover, GregorianCalendar implements the Julian calendar. The only difference between the Gregorian and the Julian calendar is the leap year rule. The Julian calendar specifies leap years every four years, whereas the Gregorian calendar omits century years which are not divisible by 400.

GregorianCalendar implements proleptic Gregorian and Julian calendars. That is, dates are computed by extrapolating the current rules indefinitely far backward and forward in time. As a result, GregorianCalendar may be used for all years to generate meaningful and consistent results. However, dates obtained using GregorianCalendar are historically accurate only from March 1, 4 AD onward, when modern Julian calendar rules were adopted. Before this date, leap year rules were applied irregularly, and before 45 BC the Julian calendar did not even exist.

Prior to the institution of the Gregorian calendar, New Year's Day was March 25. To avoid confusion, this calendar always uses January 1. A manual adjustment may be made if desired for dates that are prior to the Gregorian changeover and which fall between January 1 and March 24.

Values calculated for the WEEK_OF_YEAR field range from 1 to 53. Week 1 for a year is the earliest seven day period starting on getFirstDayOfWeek() that contains at least getMinimalDaysInFirstWeek() days from that year. It thus depends on the values of getMinimalDaysInFirstWeek(), getFirstDayOfWeek(), and the day of the week of January 1. Weeks between week 1 of one year and week 1 of the following year are numbered sequentially from 2 to 52 or 53 (as needed).

For example, January 1, 1998 was a Thursday. If getFirstDayOfWeek() is MONDAY and getMinimalDaysInFirstWeek() is 4 (these are the values reflecting ISO 8601 and many national standards), then week 1 of 1998 starts on December 29, 1997, and ends on January 4, 1998. If, however, getFirstDayOfWeek() is SUNDAY, then week 1 of 1998 starts on January 4, 1998, and ends on January 10, 1998; the first three days of 1998 then are part of week 53 of 1997.

Values calculated for the WEEK_OF_MONTH field range from 0 to 6. Week 1 of a month (the days with WEEK_OF_MONTH = 1) is the earliest set of at least getMinimalDaysInFirstWeek() contiguous days in that month, ending on the day before getFirstDayOfWeek(). Unlike week 1 of a year, week 1 of a month may be shorter than 7 days, need not start on getFirstDayOfWeek(), and will not include days of the previous month. Days of a month before week 1 have a WEEK_OF_MONTH of 0.

For example, if getFirstDayOfWeek() is SUNDAY and getMinimalDaysInFirstWeek() is 4, then the first week of January 1998 is Sunday, January 4 through Saturday, January 10. These days have a WEEK_OF_MONTH of 1. Thursday, January 1 through Saturday, January 3 have a WEEK_OF_MONTH of 0. If getMinimalDaysInFirstWeek() is changed to 3, then January 1 through January 3 have a WEEK_OF_MONTH of 1.

The clear methods set calendar field(s) undefined. GregorianCalendar uses the following default value for each calendar field if its value is undefined.

Field
Default Value
ERA
AD
YEAR
1970
MONTH
JANUARY
DAY_OF_MONTH
1
DAY_OF_WEEK
the first day of week
WEEK_OF_MONTH
0
DAY_OF_WEEK_IN_MONTH
1
AM_PM
AM
HOUR, HOUR_OF_DAY, MINUTE, SECOND, MILLISECOND
0

Default values are not applicable for the fields not listed above.

Example:

 // get the supported ids for GMT-08:00 (Pacific Standard Time)
 String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
 // if no ids were returned, something is wrong. get out.
 if (ids.length == 0)
     System.exit(0);

  // begin output
 System.out.println("Current Time");

 // create a Pacific Standard Time time zone
 SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);

 // set up rules for daylight savings time
 pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
 pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);

 // create a GregorianCalendar with the Pacific Daylight time zone
 // and the current date and time
 Calendar calendar = new GregorianCalendar(pdt);
 Date trialTime = new Date();
 calendar.setTime(trialTime);

 // print out a bunch of interesting things
 System.out.println("ERA: " + calendar.get(Calendar.ERA));
 System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
 System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
 System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
 System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
 System.out.println("DATE: " + calendar.get(Calendar.DATE));
 System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
 System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
 System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
 System.out.println("DAY_OF_WEEK_IN_MONTH: "
                    + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
 System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
 System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
 System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
 System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
 System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
 System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
 System.out.println("ZONE_OFFSET: "
                    + (calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000)));
 System.out.println("DST_OFFSET: "
                    + (calendar.get(Calendar.DST_OFFSET)/(60*60*1000)));
 System.out.println("Current Time, with hour reset to 3");
 calendar.clear(Calendar.HOUR_OF_DAY); // so doesn't override
 calendar.set(Calendar.HOUR, 3);
 System.out.println("ERA: " + calendar.get(Calendar.ERA));
 System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
 System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
 System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
 System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
 System.out.println("DATE: " + calendar.get(Calendar.DATE));
 System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
 System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
 System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
 System.out.println("DAY_OF_WEEK_IN_MONTH: "
                    + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
 System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
 System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
 System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
 System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
 System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
 System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
 System.out.println("ZONE_OFFSET: "
        + (calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000))); // in hours
 System.out.println("DST_OFFSET: "
        + (calendar.get(Calendar.DST_OFFSET)/(60*60*1000))); // in hours
 
Since:
JDK1.1
See Also:
TimeZone, Serialized Form

Field Summary

static int
AD
Value of the ERA field indicating the common era (Anno Domini), also known as CE.
static int
BC
Value of the ERA field indicating the period before the common era (before Christ), also known as BCE.

Fields inherited from class java.util.Calendar

AM, AM_PM, APRIL, AUGUST, DATE, DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_WEEK_IN_MONTH, DAY_OF_YEAR, DECEMBER, DST_OFFSET, ERA, FEBRUARY, FIELD_COUNT, FRIDAY, HOUR, HOUR_OF_DAY, JANUARY, JULY, JUNE, MARCH, MAY, MILLISECOND, MINUTE, MONDAY, MONTH, NOVEMBER, OCTOBER, PM, SATURDAY, SECOND, SEPTEMBER, SUNDAY, THURSDAY, TUESDAY, UNDECIMBER, WEDNESDAY, WEEK_OF_MONTH, WEEK_OF_YEAR, YEAR, ZONE_OFFSET, areFieldsSet, fields, isSet, isTimeSet, time

Constructor Summary

GregorianCalendar()
Constructs a default GregorianCalendar using the current time in the default time zone with the default locale.
GregorianCalendar(int year, int month, int dayOfMonth)
Constructs a GregorianCalendar with the given date set in the default time zone with the default locale.
GregorianCalendar(int year, int month, int dayOfMonth, int hourOfDay, int minute)
Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale.
GregorianCalendar(int year, int month, int dayOfMonth, int hourOfDay, int minute, int second)
Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale.
GregorianCalendar(Locale aLocale)
Constructs a GregorianCalendar based on the current time in the default time zone with the given locale.
GregorianCalendar(TimeZone zone)
Constructs a GregorianCalendar based on the current time in the given time zone with the default locale.
GregorianCalendar(TimeZone zone, Locale aLocale)
Constructs a GregorianCalendar based on the current time in the given time zone with the given locale.

Method Summary

void
add(int field, int amount)
Adds the specified (signed) amount of time to the given calendar field, based on the calendar's rules.
Object
clone()
Creates and returns a copy of this object.
protected void
computeFields()
Converts the time value (millisecond offset from the Epoch) to calendar field values.
protected void
computeTime()
Converts calendar field values to the time value (millisecond offset from the Epoch).
boolean
equals(Object obj)
Compares this GregorianCalendar to the specified Object.
int
getActualMaximum(int field)
Returns the maximum value that this calendar field could have, taking into consideration the given time value and the current values of the getFirstDayOfWeek, getMinimalDaysInFirstWeek, getGregorianChange and getTimeZone methods.
int
getActualMinimum(int field)
Returns the minimum value that this calendar field could have, taking into consideration the given time value and the current values of the getFirstDayOfWeek, getMinimalDaysInFirstWeek, getGregorianChange and getTimeZone methods.
int
getGreatestMinimum(int field)
Returns the highest minimum value for the given calendar field of this GregorianCalendar instance.
Date
getGregorianChange()
Gets the Gregorian Calendar change date.
int
getLeastMaximum(int field)
Returns the lowest maximum value for the given calendar field of this GregorianCalendar instance.
int
getMaximum(int field)
Returns the maximum value for the given calendar field of this GregorianCalendar instance.
int
getMinimum(int field)
Returns the minimum value for the given calendar field of this GregorianCalendar instance.
TimeZone
getTimeZone()
int
hashCode()
Generates the hash code for this GregorianCalendar object.
boolean
isLeapYear(int year)
Determines if the given year is a leap year.
void
roll(int field, boolean up)
Adds or subtracts (up/down) a single unit of time on the given time field without changing larger fields.
void
roll(int field, int amount)
Adds a signed amount to the specified calendar field without changing larger fields.
void
setGregorianChange(Date date)
Sets the GregorianCalendar change date.
void
setTimeZone(TimeZone zone)

Methods inherited from class java.util.Calendar

add, after, before, clear, clear, clone, compareTo, complete, computeFields, computeTime, equals, get, getActualMaximum, getActualMinimum, getAvailableLocales, getFirstDayOfWeek, getGreatestMinimum, getInstance, getInstance, getInstance, getInstance, getLeastMaximum, getMaximum, getMinimalDaysInFirstWeek, getMinimum, getTime, getTimeInMillis, getTimeZone, hashCode, internalGet, isLenient, isSet, roll, roll, set, set, set, set, setFirstDayOfWeek, setLenient, setMinimalDaysInFirstWeek, setTime, setTimeInMillis, setTimeZone, toString

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

AD
Value of the ERA field indicating the common era (Anno Domini), also known as CE. The sequence of years at the transition from BC to AD is ..., 2 BC, 1 BC, 1 AD, 2 AD,...
Field Value:
1
See Also:
Calendar.ERA
Usages and Demos :

View More Examples of GregorianCalendar.AD
   1:     cal.set(Calendar.DST_OFFSET, 0);
   2:     cal.set(Calendar.ERA, negative ? GregorianCalendar.BC : GregorianCalendar.AD);
   3:     month -= 1;
   4:     cal.set(year, month, day, hours, minutes, seconds);
   5:     cal.set(Calendar.MILLISECOND, milliseconds);

View Full Code Here
   1:             {
   2:                 set(Calendar.ERA, GregorianCalendar.AD);
   3:             }
   4:             else
   5:             {

View Full Code Here
   1:             } else {
   2:                 newdate.set(GregorianCalendar.ERA, GregorianCalendar.AD);
   3:             }
   4:         ...
   5: 
   6:         if (date.get(Calendar.ERA) == GregorianCalendar.AD) {
   7:             number = ((4000 + date.get(Calendar.YEAR)) * 10000) + (date.get(Calendar.MONTH) * 100) + date.get(Calendar.DAY_OF_MONTH);
   8:         } else {
   9:             number = ((4000 - date.get(Calendar.YEAR)) * 10000) + (date.get(Calendar.MONTH) * 100) + date.get(Calendar.DAY_OF_MONTH);

View Full Code Here
   1:       try {
   2:         long offset = _localTimeZone.getOffset(GregorianCalendar.AD,
   3:                                                (int) _year,
   4:         ...
   5:     else {
   6:       long offset = _localTimeZone.getOffset(GregorianCalendar.AD,
   7:                                              (int) _year,
   8:         ...
   9:     else {
  10:       _zoneOffset = _timeZone.getOffset(GregorianCalendar.AD,
  11:                                         (int) _year,

View Full Code Here
   1:             if (eon == null) {
   2:                 result.set(Calendar.ERA, year < 0 ? GregorianCalendar.BC : GregorianCalendar.AD);
   3:                 result.set(Calendar.YEAR, Math.abs(year));
   4:         ...
   5:                 BigInteger eonAndYear = getEonAndYear();
   6:                 result.set(Calendar.ERA, eonAndYear.signum() == -1 ? GregorianCalendar.BC : GregorianCalendar.AD);
   7:                 result.set(Calendar.YEAR, eonAndYear.abs().intValue());
   8:         ...
   9:             if (eon == null) {
  10:                 result.set(Calendar.ERA, year < 0 ? GregorianCalendar.BC : GregorianCalendar.AD);
  11:                 result.set(Calendar.YEAR, Math.abs(year));

View Full Code Here

BC

public static final int BC
Value of the ERA field indicating the period before the common era (before Christ), also known as BCE. The sequence of years at the transition from BC to AD is ..., 2 BC, 1 BC, 1 AD, 2 AD,...
Field Value:
0
See Also:
Calendar.ERA
Usages and Demos :

View More Examples of GregorianCalendar.BC
   1:     cal.set(Calendar.DST_OFFSET, 0);
   2:     cal.set(Calendar.ERA, negative ? GregorianCalendar.BC : GregorianCalendar.AD);
   3:     month -= 1;
   4:     cal.set(year, month, day, hours, minutes, seconds);
   5:     cal.set(Calendar.MILLISECOND, milliseconds);

View Full Code Here
   1:             {
   2:                 set(Calendar.ERA, GregorianCalendar.BC);
   3:                 y = 1 - y;
   4:             }
   5:             set(Calendar.YEAR, y);

View Full Code Here
   1:             if (year < 0) {
   2:                 calendar.set(Calendar.ERA, GregorianCalendar.BC);
   3:             }
   4:         ...
   5:         int year = calendar.get(Calendar.YEAR);
   6:         if (era == GregorianCalendar.BC) {
   7:             sb.append('-');
   8:         }
   9:         DateTimeValue.appendString(sb, year, (year>9999 ? (calendar.get(Calendar.YEAR)+"").length() : 4));

View Full Code Here
   1:             int startYear = minDate.get(Calendar.YEAR);
   2:             if (minDate instanceof GregorianCalendar && startEra == GregorianCalendar.BC) startYear = -1 * (startYear - 1);
   3:             int endYear = maxDate.get(Calendar.YEAR);
   4:         ...
   5:             if (maxDate instanceof GregorianCalendar && endEra == GregorianCalendar.BC) endYear = -1 * (endYear - 1);
   6:             return new Element("year",  Calendar.YEAR,  startYear, endYear) {
   7:         ...
   8:                     int year  = cal.get(Calendar.YEAR);
   9:                     if (cal instanceof GregorianCalendar && era == GregorianCalendar.BC) year = -1 * (year - 1);
  10:                     return year;

View Full Code Here
   1:             if (bc) {
   2:                 newdate.set(GregorianCalendar.ERA, GregorianCalendar.BC);
   3:             } else {
   4:                 newdate.set(GregorianCalendar.ERA, GregorianCalendar.AD);
   5:             }

View Full Code Here

Constructor Details

GregorianCalendar

public GregorianCalendar()
Constructs a default GregorianCalendar using the current time in the default time zone with the default locale.
Usages and Demos :

View More Examples of GregorianCalendar()
   1: 
   2:         Customer customer = new Customer(customerId, "FirstName " + id, "LastName " + id, Integer.toString(id), new GregorianCalendar(), Integer.toString(id), Integer.toString(id), bill, ship);
   3: 
   4:         ...
   5:         
   6:         Order order = new Order(orderId, 1, new GregorianCalendar(), (float) 50, customer, (LineItem[])lines.toArray(new LineItem[0]) );
   7: 
   8:         return order;
   9:     }

View Full Code Here
   1:     protected List createReflectableObjects() {
   2:         Calendar calendar = new GregorianCalendar();
   3:         calendar.setTime(new Date());
   4:         ...
   5:         List list = new ArrayList();
   6:         list.add(new GregorianCalendar());
   7:         list.add(calendar);
   8:         return list;
   9:     }

View Full Code Here
   1: 
   2:         Calendar calendar = new GregorianCalendar();
   3:         calendar.setTime(new Date());
   4:         ...
   5:         list.add(new GregorianCalendar());
   6:         list.add(calendar);
   7:         
   8:         list.add(new StringBuffer());

View Full Code Here
   1:     property.setValue(true);
   2:     property.setValue(new GregorianCalendar());
   3:     property.setValue(20D);
   4:     property.setValue(20L); 
   5:     

View Full Code Here

GregorianCalendar

public GregorianCalendar(int year,
                         int month,
                         int dayOfMonth)
Constructs a GregorianCalendar with the given date set in the default time zone with the default locale.
Parameters:
year - the value used to set the YEAR calendar field in the calendar.
month - the value used to set the MONTH calendar field in the calendar. Month value is 0-based. e.g., 0 for January.
dayOfMonth - the value used to set the DAY_OF_MONTH calendar field in the calendar.
Usages and Demos :

View More Examples of GregorianCalendar(int year,int month,int dayOfMonth)
   1:     public static void main(String[] argv) {
   2:         Calendar c = new GregorianCalendar(1918, 10, 11);
   3:         System.out.println(c.get(Calendar.DAY_OF_MONTH) + " " +
   4:             c.get(Calendar.MONTH) + ", " +
   5:             c.get(Calendar.YEAR) + " " +

View Full Code Here
   1:     public static void main(String[] argv) {
   2:         Calendar c = new GregorianCalendar(1918, 10, 11);
   3:         System.out.println(
   4:             months[c.get(Calendar.MONTH)] + " " +
   5:             c.get(Calendar.DAY_OF_MONTH) + ", " +

View Full Code Here
   1:     
   2:     private final GregorianCalendar cal = new GregorianCalendar(0,0,0);
   3:     
   4:     private CalendarParser( String format, String value ) {
   5:         super(format,value);

View Full Code Here
   1:       "Clay", "Ashworth", 
   2:       new GregorianCalendar(1962, Calendar.FEBRUARY, 20).getTime(), 
   3:       new Float(12345.67), new Boolean(GENDER_MALE)
   4:         ...
   5:       "Jacob", "Ashworth", 
   6:       new GregorianCalendar(1987, Calendar.JANUARY, 6).getTime(), 
   7:       new Float(23456.78), new Boolean(GENDER_MALE)
   8:         ...
   9:       "Jordan", "Ashworth", 
  10:       new GregorianCalendar(1989, Calendar.AUGUST, 31).getTime(), 
  11:       new Float(34567.89), new Boolean(GENDER_FEMALE)

View Full Code Here

GregorianCalendar

public GregorianCalendar(int year,
                         int month,
                         int dayOfMonth,
                         int hourOfDay,
                         int minute)
Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale.
Parameters:
year - the value used to set the YEAR calendar field in the calendar.
month - the value used to set the MONTH calendar field in the calendar. Month value is 0-based. e.g., 0 for January.
dayOfMonth - the value used to set the DAY_OF_MONTH calendar field in the calendar.
hourOfDay - the value used to set the HOUR_OF_DAY calendar field in the calendar.
minute - the value used to set the MINUTE calendar field in the calendar.
Usages and Demos :

View More Examples of GregorianCalendar(int year,int month,int dayOfMonth,int hourOfDay,int minute)
   1:     public static void main(String[] av) {
   2:         Date d1 = new GregorianCalendar(1999,11,31,23,59).getTime();

View Full Code Here
   1:       System.currentTimeMillis()
   2:         > new GregorianCalendar(1999, 11, 00, 00, 00).getTime().getTime());
   3:   }
   4: }

View Full Code Here
   1:             int minute) { 
   2:         calendar = new GregorianCalendar(year, month, day, hour, minute);
   3:     }
   4: 
   5:     public GregorianCalendarAdapter(int year, int month, int day, int hour,

View Full Code Here
   1:         airFrance.setDepartureDate( new Date( 05, 06, 21, 10, 0, 0 ) );
   2:         airFrance.setAlternativeDepartureDate( new GregorianCalendar( 2006, 02, 03, 10, 00 ) );
   3:         airFrance.getAlternativeDepartureDate().setTimeZone( TimeZone.getTimeZone( "GMT" ) );
   4:         airFrance.setBuyDate( new java.sql.Timestamp(122367443) );
   5:         airFrance.setFactor( 25 );

View Full Code Here
   1: 
   2:       controller.setTimeParameters( (new GregorianCalendar(2001, 7, 21, 1, 0)).getTime(),
   3:                                      1L * DurationType.MILTOHR,
   4:         ...
   5: 
   6:       controller.setTimeParameters( (new GregorianCalendar(2001, 7, 21, 1, 0)).getTime(),
   7:                                     1L * DurationType.MILTOHR,
   8:                                     9L * DurationType.MILTOHR );
   9:       scenario.addMObject(controller);

View Full Code Here

GregorianCalendar

public GregorianCalendar(int year,
                         int month,
                         int dayOfMonth,
                         int hourOfDay,
                         int minute,
                         int second)
Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale.
Parameters:
year - the value used to set the YEAR calendar field in the calendar.
month - the value used to set the MONTH calendar field in the calendar. Month value is 0-based. e.g., 0 for January.
dayOfMonth - the value used to set the DAY_OF_MONTH calendar field in the calendar.
hourOfDay - the value used to set the HOUR_OF_DAY calendar field in the calendar.
minute - the value used to set the MINUTE calendar field in the calendar.
second - the value used to set the SECOND calendar field in the calendar.
Usages and Demos :

View More Examples of GregorianCalendar(int year,int month,int dayOfMonth,int hourOfDay,int minute,int second)
   1:     private static TimeZone UTC = new SimpleTimeZone(0,"UTC");
   2:     private static Calendar c = new GregorianCalendar(1900,Calendar.JANUARY,1,0,0,0);
   3:     private static Date startOfCentury;
   4: 

View Full Code Here
   1:    {
   2:       g1 = new GregorianCalendar(1952, 0, 1, 12, 10, 8);
   3:         ...
   4:       g2 = new GregorianCalendar(2002, 6, 2, 12, 10, 9);
   5:    }
   6: 
   7:    protected void tearDown()

View Full Code Here
   1: 
   2:       Calendar cal1 = new GregorianCalendar(1968, 5, 16, 14, 23, 55);
   3:       cal1.setTimeZone(TimeZone.getTimeZone("GMT"));
   4:         ...
   5:       Calendar cal2 = new GregorianCalendar(1969, 6, 17, 15, 24, 56);
   6:       cal2.setTimeZone(TimeZone.getTimeZone("GMT"));
   7:         ...
   8:       Calendar cal3 = new GregorianCalendar(1970, 7, 18, 16, 25, 57);
   9:       cal3.setTimeZone(TimeZone.getTimeZone("GMT"));

View Full Code Here
   1:         if (c == null) {
   2:             c = new GregorianCalendar(1970, 0, 1, 0, 0, 0);
   3:             c.setTimeZone(SystemTime.UTC_TIMEZONE);
   4:             int year = Integer.parseInt(value.substring(0, 4));
   5:             int month = Integer.parseInt(value.substring(4, 6));

View Full Code Here
   1:    {
   2:       Calendar cal1 = new GregorianCalendar(1968, 5, 16, 14, 23, 55);
   3:       cal1.setTimeZone(TimeZone.getTimeZone("GMT"));
   4:         ...
   5:       Calendar cal2 = new GregorianCalendar(1969, 6, 17, 15, 24, 56);
   6:       cal2.setTimeZone(TimeZone.getTimeZone("GMT"));
   7:         ...
   8:       Calendar cal3 = new GregorianCalendar(1970, 7, 18, 16, 25, 57);
   9:       cal3.setTimeZone(TimeZone.getTimeZone("GMT"));

View Full Code Here

GregorianCalendar

public GregorianCalendar(Locale aLocale)
Constructs a GregorianCalendar based on the current time in the default time zone with the given locale.
Parameters:
aLocale - the given locale.
Usages and Demos :

View More Examples of GregorianCalendar(Locale aLocale)
   1:     {
   2:         GregorianCalendar cal = new GregorianCalendar(Language.getLoginLanguage().getLocale());
   3:         String Year = String.valueOf(cal.get(Calendar.YEAR));
   4:         ...
   5:         int year = getYearAsInt();
   6:         GregorianCalendar cal = new GregorianCalendar(locale);
   7:         cal.set(Calendar.HOUR_OF_DAY, 0);
   8:         cal.set(Calendar.MINUTE, 0);
   9:         cal.set(Calendar.SECOND, 0);

View Full Code Here
   1:     java.util.Calendar 
   2:       cal = new java.util.GregorianCalendar( Default.timezone );
   3:     
   4:     cal.setTime( new java.util.Date() );
   5:     

View Full Code Here
   1:       {
   2:         greg = new GregorianCalendar(((Date)this.getMemberValue()).getYear(),((Date)this.getMemberValue()).getMonth(),((Date)this.getMemberValue()).getDate(),((Date)this.getMemberValue()).getHours(),((Date)this.getMemberValue()).getMinutes());
   3:       }catch(Exception e){
   4:                 isTimestamp = true;
   5:                 greg = new GregorianCalendar();

View Full Code Here
   1:       java.util.Calendar 
   2:         cal = new java.util.GregorianCalendar( Default.timezone );
   3:     
   4:       cal.setTime( new java.util.Date() );
   5:     

View Full Code Here

GregorianCalendar

public GregorianCalendar(TimeZone zone)
Constructs a GregorianCalendar based on the current time in the given time zone with the default locale.
Parameters:
zone - the given time zone.
Usages and Demos :

View More Examples of GregorianCalendar(TimeZone zone)
   1:     {
   2:         GregorianCalendar cal = new GregorianCalendar(Language.getLoginLanguage().getLocale());
   3:         String Year = String.valueOf(cal.get(Calendar.YEAR));
   4:         ...
   5:         int year = getYearAsInt();
   6:         GregorianCalendar cal = new GregorianCalendar(locale);
   7:         cal.set(Calendar.HOUR_OF_DAY, 0);
   8:         cal.set(Calendar.MINUTE, 0);
   9:         cal.set(Calendar.SECOND, 0);

View Full Code Here
   1:     java.util.Calendar 
   2:       cal = new java.util.GregorianCalendar( Default.timezone );
   3:     
   4:     cal.setTime( new java.util.Date() );
   5:     

View Full Code Here
   1:       {
   2:         greg = new GregorianCalendar(((Date)this.getMemberValue()).getYear(),((Date)this.getMemberValue()).getMonth(),((Date)this.getMemberValue()).getDate(),((Date)this.getMemberValue()).getHours(),((Date)this.getMemberValue()).getMinutes());
   3:       }catch(Exception e){
   4:                 isTimestamp = true;
   5:                 greg = new GregorianCalendar();

View Full Code Here
   1:       java.util.Calendar 
   2:         cal = new java.util.GregorianCalendar( Default.timezone );
   3:     
   4:       cal.setTime( new java.util.Date() );
   5:     

View Full Code Here

GregorianCalendar

public GregorianCalendar(TimeZone zone,
                         Locale aLocale)
Constructs a GregorianCalendar based on the current time in the given time zone with the given locale.
Parameters:
zone - the given time zone.
aLocale - the given locale.
Usages and Demos :

View More Examples of GregorianCalendar(TimeZone zone,Locale aLocale)
   1:   public void actionPerformed(ActionEvent e) {
   2:     Calendar calendar = new GregorianCalendar(timeZone, getLocale());
   3:     clock.setHour(calendar.get(Calendar.HOUR));
   4:     clock.setMinute(calendar.get(Calendar.MINUTE));
   5:     clock.setSecond(calendar.get(Calendar.SECOND));

View Full Code Here
   1: 
   2:         cal = new GregorianCalendar(tz, Locale.getDefault());
   3:         day = cal.get(Calendar.DAY_OF_MONTH);
   4:         hr = cal.get(Calendar.HOUR_OF_DAY);
   5:         mn = cal.get(Calendar.MINUTE);

View Full Code Here
   1: 
   2:         Calendar cal = new GregorianCalendar(year, intToCalendarMonth(month), 
   3:             day, hour, minute);
   4:         ...
   5: 
   6:         Calendar cal = new GregorianCalendar(year, intToCalendarMonth(month), 
   7:             day);
   8: 
   9:         return cal.getTime();

View Full Code Here
   1:     try {
   2:       GregorianCalendar currentDate = new GregorianCalendar(tz, locale);
   3:       dateForm.set("currentDate", currentDate);
   4:       request.setAttribute("currentDate", currentDate);
   5:       Integer dateTimeType = (Integer) dateForm.get("dateTimeType");

View Full Code Here
   1: 
   2:         Calendar cal = new GregorianCalendar(year, intToCalendarMonth(month),
   3:             day, hour, minute);
   4:         ...
   5: 
   6:         Calendar cal = new GregorianCalendar(year, intToCalendarMonth(month),
   7:             day);
   8: 
   9:         return cal.getTime();

View Full Code Here

Method Details

add

public void add(int field,
                int amount)
Adds the specified (signed) amount of time to the given calendar field, based on the calendar's rules.

Add rule 1. The value of field after the call minus the value of field before the call is amount, modulo any overflow that has occurred in field. Overflow occurs when a field value exceeds its range and, as a result, the next larger field is incremented or decremented and the field value is adjusted back into its range.

Add rule 2. If a smaller field is expected to be invariant, but it is impossible for it to be equal to its prior value because of changes in its minimum or maximum after field is changed, then its value is adjusted to be as close as possible to its expected value. A smaller field represents a smaller unit of time. HOUR is a smaller field than DAY_OF_MONTH. No adjustment is made to smaller fields that are not expected to be invariant. The calendar system determines what fields are expected to be invariant.

Overrides:
add in interface Calendar
Parameters:
field - the calendar field.
amount - the amount of date or time to be added to the field.
Throws:
IllegalArgumentException - if field is ZONE_OFFSET, DST_OFFSET, or unknown, or if any calendar fields have out-of-range values in non-lenient mode.
Usages and Demos :

View More Examples of add(int field,int amount)
   1: 
   2:     GregorianCalendar gc = new GregorianCalendar();
   3:     int year = gc.get(Calendar.YEAR);
   4:         ...
   5: 
   6:     gc.add(Calendar.DATE, -date + 1);
   7: 
   8:     int fdow = gc.get(Calendar.DAY_OF_WEEK);

View Full Code Here
   1: import java.util.Calendar;
   2: import java.util.GregorianCalendar;
   3: 
   4:         ...
   5: 
   6:         if (!cal.getClass().equals(GregorianCalendar.class))
   7:         ...
   8:             GregorianCalendar gc = new GregorianCalendar();
   9:             gc.setTime(cal.getTime());
  10:         ...
  11: 
  12:             gc.add(field, amount);

View Full Code Here
   1: 
   2:     GregorianCalendar gc = new GregorianCalendar();
   3: 
   4:         ...
   5:     int date = gc.get(Calendar.DATE);
   6:     gc.add(Calendar.DATE, -(date - 1));
   7: 
   8:     int year = gc.get(Calendar.YEAR);
   9:     int month = gc.get(Calendar.MONTH);

View Full Code Here
   1: 
   2:     private GregorianCalendar calendar;
   3: 
   4:         ...
   5:     public GregorianCalendarAdapter(GregorianCalendar calendar) {
   6:         this.calendar = calendar;
   7:         ...
   8:     public GregorianCalendarAdapter(int year, int month, int day) {
   9:         calendar = new GregorianCalendar(year, month, day);
  10:     }
  11:         ...
  12:     public void add(int field, int amount) {
  13:         calendar.add(field, amount);

View Full Code Here
   1: import java.util.Date;
   2: import java.util.GregorianCalendar;
   3: 
   4:         ...
   5:         
   6:         GregorianCalendar cal = new GregorianCalendar();
   7:         if( ( time == null || time.length() == 0 ) && "0".equals(frequency)) {
   8:         ...
   9:             cal.add(Calendar.DATE, 1);
  10:             startTime = Util.truncateDate(cal.getTime());
  11:         ...
  12:             }
  13:             cal.add(Calendar.MINUTE, interval);

View Full Code Here

clone

public Object clone()
Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:
 x.clone() != x
will be true, and that the expression:
 x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
 x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

The method clone for class Object performs a specific cloning operation. First, if the class of this object does not implement the interface Cloneable, then a CloneNotSupportedException is thrown. Note that all arrays are considered to implement the interface Cloneable. Otherwise, this method creates a new instance of the class of this object and initializes all its fields with exactly the contents of the corresponding fields of this object, as if by assignment; the contents of the fields are not themselves cloned. Thus, this method performs a "shallow copy" of this object, not a "deep copy" operation.

The class Object does not itself implement the interface Cloneable, so calling the clone method on an object whose class is Object will result in throwing an exception at run time.

Overrides:
clone in interface Calendar
Returns:
a clone of this instance.
See Also:
Cloneable
Usages and Demos :

View More Examples of clone()
   1: import java.util.Date;
   2: import java.util.GregorianCalendar;
   3: import java.util.TimeZone;
   4:         ...
   5:   private Date startDate;
   6:   private GregorianCalendar startCalendar;
   7: 
   8:         ...
   9:     this.startDate = startDate;
  10:     startCalendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
  11:     startCalendar.setTime(startDate);
  12:         ...
  13:     String labels[] = new String[numberOfIntervals];
  14:     GregorianCalendar nextCalendar = (GregorianCalendar)startCalendar.clone();

View Full Code Here
   1: import java.util.Date;
   2: import java.util.GregorianCalendar;
   3: import java.util.Locale;
   4:         ...
   5: 
   6:         GregorianCalendar now = new GregorianCalendar();
   7:         ...
   8:         GregorianCalendar lastModified = (GregorianCalendar)now.clone();
   9:         lastModified.setTimeInMillis(dateLastModified.getTime());

View Full Code Here
   1: import java.util.Date;
   2: import java.util.GregorianCalendar;
   3: import java.util.HashMap;
   4:         ...
   5:         
   6:         GregorianCalendar today = new GregorianCalendar(TimeZone.getDefault(), CmsLocaleManager.getDefaultLocale()); 
   7:         today.setTimeInMillis(cms.getRequestContext().getRequestTime());
   8:         ...
   9:         GregorianCalendar inFiveDays = (GregorianCalendar)today.clone();
  10:         inFiveDays.add(Calendar.DAY_OF_YEAR, 5);
  11:         ...
  12:         GregorianCalendar inEightDays = (GregorianCalendar)today.clone();

View Full Code Here
   1: import java.util.Date;
   2: import java.util.GregorianCalendar;
   3: import java.util.HashMap;
   4:         ...
   5:         String folder = "/";
   6:         GregorianCalendar now = new GregorianCalendar(TimeZone.getDefault(), CmsLocaleManager.getDefaultLocale());
   7:         now.setTimeInMillis(System.currentTimeMillis());
   8:         ...
   9:         GregorianCalendar inOneWeek = (GregorianCalendar)now.clone();
  10:         inOneWeek.add(Calendar.WEEK_OF_YEAR, 1);
  11:         ...
  12:                 intervalBefore.add(Calendar.DAY_OF_YEAR, notification_interval);
  13:                 GregorianCalendar intervalAfter = (GregorianCalendar)intervalBefore.clone();

View Full Code Here
   1: import java.util.Date;
   2: import java.util.GregorianCalendar;
   3: import java.util.Locale;
   4:         ...
   5:     
   6:     public XMLGregorianCalendarImpl(GregorianCalendar cal) {
   7: 
   8:         ...
   9:         int year = cal.get(Calendar.YEAR);
  10:         if (cal.get(Calendar.ERA) == GregorianCalendar.BC) {
  11:             year = -year;
  12:         ...
  13:         int minutes = timezone;        
  14:         XMLGregorianCalendar result = (XMLGregorianCalendar) cal.clone();

View Full Code Here

computeFields

protected void computeFields()
Converts the time value (millisecond offset from the Epoch) to calendar field values. The time is not recomputed first; to recompute the time, then the fields, call the complete method.
Overrides:
computeFields in interface Calendar

computeTime

protected void computeTime()
Converts calendar field values to the time value (millisecond offset from the Epoch).
Overrides:
computeTime in interface Calendar
Throws:
IllegalArgumentException - if any calendar fields are invalid.

equals

public boolean equals(Object obj)
Compares this GregorianCalendar to the specified Object. The result is true if and only if the argument is a GregorianCalendar object that represents the same time value (millisecond offset from the Epoch) under the same Calendar parameters and Gregorian change date as this object.
Overrides:
equals in interface Calendar
Parameters:
obj - the object to compare with.
Returns:
true if this object is equal to obj; false otherwise.

getActualMaximum

public int getActualMaximum(int field)
Returns the maximum value that this calendar field could have, taking into consideration the given time value and the current values of the getFirstDayOfWeek, getMinimalDaysInFirstWeek, getGregorianChange and getTimeZone methods. For example, if the date of this instance is February 1, 2004, the actual maximum value of the DAY_OF_MONTH field is 29 because 2004 is a leap year, and if the date of this instance is February 1, 2005, it's 28.
Overrides:
getActualMaximum in interface Calendar
Parameters:
field - the calendar field
Returns:
the maximum of the given field for the time value of this GregorianCalendar
Since:
1.2
Usages and Demos :

View More Examples of getActualMaximum(int field)
   1:   {
   2:     GregorianCalendar cal = new GregorianCalendar();
   3: 
   4:         ...
   5:       System.out.println( (month+1) + " : " +
   6:         cal.getActualMaximum(Calendar.DAY_OF_MONTH) );
   7:     }
   8:   }
   9: }

View Full Code Here
   1: import java.util.Calendar;
   2: import java.util.GregorianCalendar;
   3: 
   4:         ...
   5:                 invoice.getDueDatePeriod().getDf_fm().booleanValue()) {
   6:             GregorianCalendar cal = new GregorianCalendar();
   7:             cal.setTime(invoice.getDueDate());
   8:         ...
   9:             int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
  10:             cal.set(Calendar.DAY_OF_MONTH, lastDay);

View Full Code Here
   1: import java.util.Calendar;
   2: import java.util.GregorianCalendar;
   3: import java.util.LinkedList;
   4:         ...
   5:             Calendar endCal = Calendar.getInstance();
   6:             GregorianCalendar monthCal = new GregorianCalendar();
   7:             
   8:         ...
   9:                     
  10:                     monthCal.set(Calendar.DATE, monthCal.getActualMaximum(Calendar.DATE) );
  11:                     Date endDate = new Date(monthCal.getTime().getTime());

View Full Code Here
   1:     protected Calendar calcDate(boolean start, int shift, int shiftUnit, int dayInShiftUnit) {
   2:         GregorianCalendar calendar = new GregorianCalendar();
   3: 
   4:         ...
   5:         else
   6:             calendar.set(dayInShiftUnit, calendar.getActualMaximum(dayInShiftUnit));
   7: 
   8:         if (start) {
   9:             calendar.set(Calendar.HOUR_OF_DAY, 0);

View Full Code Here
   1:     {
   2:         GregorianCalendar cal = new GregorianCalendar();
   3:         cal.setTime(DocDate);
   4:         ...
   5:         cal.set(Calendar.MILLISECOND, 0);
   6:         int maxDayCut = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
   7:             cal.set(Calendar.DAY_OF_MONTH, maxDayCut);
   8:         ...
   9:         cal.add(Calendar.MONTH, FixMonthOffset);
  10:         int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
  11:             cal.set(Calendar.DAY_OF_MONTH, maxDay);

View Full Code Here

getActualMinimum

public int getActualMinimum(int field)
Returns the minimum value that this calendar field could have, taking into consideration the given time value and the current values of the getFirstDayOfWeek, getMinimalDaysInFirstWeek, getGregorianChange and getTimeZone methods.

For example, if the Gregorian change date is January 10, 1970 and the date of this GregorianCalendar is January 20, 1970, the actual minimum value of the DAY_OF_MONTH field is 10 because the previous date of January 10, 1970 is December 27, 1996 (in the Julian calendar). Therefore, December 28, 1969 to January 9, 1970 don't exist.

Overrides:
getActualMinimum in interface Calendar
Parameters:
field - the calendar field
Returns:
the minimum of the given field for the time value of this GregorianCalendar
Since:
1.2
Usages and Demos :

View More Examples of getActualMinimum(int field)
   1: import java.util.Calendar;
   2: import java.util.GregorianCalendar;
   3: import java.util.LinkedList;
   4:         ...
   5:             Calendar endCal = Calendar.getInstance();
   6:             GregorianCalendar monthCal = new GregorianCalendar();
   7:             
   8:         ...
   9:                 {
  10:                     monthCal.set(Calendar.DATE, monthCal.getActualMinimum(Calendar.DATE) );
  11:                     Date startDate = new Date(monthCal.getTime().getTime());

View Full Code Here
   1:     protected Calendar calcDate(boolean start, int shift, int shiftUnit, int dayInShiftUnit) {
   2:         GregorianCalendar calendar = new GregorianCalendar();
   3: 
   4:         ...
   5:         if (start)
   6:             calendar.set(dayInShiftUnit, calendar.getActualMinimum(dayInShiftUnit));
   7:         else
   8:             calendar.set(dayInShiftUnit, calendar.getActualMaximum(dayInShiftUnit));

View Full Code Here
   1: import java.text.DateFormat;
   2: import java.util.GregorianCalendar;
   3: import java.util.TimeZone;
   4:         ...
   5:   }
   6:   private GregorianCalendar calendar = new GregorianCalendar(timeZone);
   7:   private Thread thread;
   8:         ...
   9:       year = calendar.get(Calendar.YEAR);
  10:       int newMonth = calendar.get(Calendar.MONTH) - calendar.getActualMinimum(Calendar.MONTH);
  11:       if (newMonth != month) {
  12:         ...
  13:           (tempCalendar.get(Calendar.DAY_OF_WEEK)
  14:            - tempCalendar.getActualMinimum(Calendar.DAY_OF_WEEK));

View Full Code Here

getGreatestMinimum

public int getGreatestMinimum(int field)
Returns the highest minimum value for the given calendar field of this GregorianCalendar instance. The highest minimum value is defined as the largest value returned by getActualMinimum(int) for any possible time value, taking into consideration the current values of the getFirstDayOfWeek, getMinimalDaysInFirstWeek, getGregorianChange and getTimeZone methods.
Overrides:
getGreatestMinimum in interface Calendar
Parameters:
field - the calendar field.
Returns:
the highest minimum value for the given calendar field.

getGregorianChange

public final Date getGregorianChange()
Gets the Gregorian Calendar change date. This is the point when the switch from Julian dates to Gregorian dates occurred. Default is October 15, 1582 (Gregorian). Previous to this, dates will be in the Julian calendar.
Returns:
the Gregorian cutover date for this GregorianCalendar object.

getLeastMaximum

public int getLeastMaximum(int field)
Returns the lowest maximum value for the given calendar field of this GregorianCalendar instance. The lowest maximum value is defined as the smallest value returned by getActualMaximum(int) for any possible time value, taking into consideration the current values of the getFirstDayOfWeek, getMinimalDaysInFirstWeek, getGregorianChange and getTimeZone methods.
Overrides:
getLeastMaximum in interface Calendar
Parameters:
field - the calendar field
Returns:
the lowest maximum value for the given calendar field.

getMaximum

public int getMaximum(int field)
Returns the maximum value for the given calendar field of this GregorianCalendar instance. The maximum value is defined as the largest value returned by the get method for any possible time value, taking into consideration the current values of the getFirstDayOfWeek, getMinimalDaysInFirstWeek, getGregorianChange and getTimeZone methods.
Overrides:
getMaximum in interface Calendar
Parameters:
field - the calendar field.
Returns:
the maximum value for the given calendar field.

getMinimum

public int getMinimum(int field)
Returns the minimum value for the given calendar field of this GregorianCalendar instance. The minimum value is defined as the smallest value returned by the get method for any possible time value, taking into consideration the current values of the getFirstDayOfWeek, getMinimalDaysInFirstWeek, getGregorianChange and getTimeZone methods.
Overrides:
getMinimum in interface Calendar
Parameters:
field - the calendar field.
Returns:
the minimum value for the given calendar field.

getTimeZone

public TimeZone getTimeZone()
Overrides:
getTimeZone in interface Calendar
Usages and Demos :

View More Examples of getTimeZone()
   1: 
   2:     private GregorianCalendar    m_calendar;
   3:     private int                 m_firstDay;
   4:         ...
   5:     {
   6:         m_calendar = new GregorianCalendar(Language.getLoginLanguage().getLocale());
   7:         if (startTS == null)
   8:         ...
   9:         cbPM.setSelected(pm);
  10:         TimeZone tz = m_calendar.getTimeZone();
  11:         lTZ.setText(tz.getDisplayName(tz.inDaylightTime(m_calendar.getTime()), TimeZone.SHORT));

View Full Code Here
   1: import java.util.Collection;
   2: import java.util.GregorianCalendar;
   3: import java.util.Iterator;
   4:         ...
   5: 
   6:     public java.util.Vector findEventsForDay(java.util.GregorianCalendar day) {
   7:         Vector returnItems = new Vector();
   8:         ...
   9:                     EventLocalHome.class);
  10:             GregorianCalendar tmpday = new java.util.GregorianCalendar();
  11:         ...
  12:             TimeZone timeZone = day.getTimeZone();

View Full Code Here

hashCode

public int hashCode()
Generates the hash code for this GregorianCalendar object.
Overrides:
hashCode in interface Calendar

isLeapYear

public boolean isLeapYear(int year)
Determines if the given year is a leap year. Returns true if the given year is a leap year. To specify BC year numbers, 1 - year number must be given. For example, year BC 4 is specified as -3.
Parameters:
year - the given year.
Returns:
true if the given year is a leap year; false otherwise.
Usages and Demos :

View More Examples of isLeapYear(int year)
   1: 
   2:     GregorianCalendar gc = new GregorianCalendar();
   3:     int year = gc.get(Calendar.YEAR);
   4:         ...
   5:     daysInMonths[1] += 
   6:       gc.isLeapYear(year) ? 1 : 0;
   7: 
   8:     gc.add(Calendar.DATE, -date + 1);

View Full Code Here
   1: 
   2:   GregorianCalendar cal;
   3: 
   4:         ...
   5:       int year = Integer.parseInt(st.nextToken());
   6:       cal = new GregorianCalendar(year, month - 1, day);
   7:     }
   8:         ...
   9:       int numdays = 30;
  10:         numdays -= cal.isLeapYear(cal.get(Calendar.YEAR))? 1 : 2;
  11:       } else if ((month <= 6 && month % 2 == 0) || 

View Full Code Here
   1: import java.util.Calendar;
   2: import java.util.GregorianCalendar;
   3: 
   4:         ...
   5:         m_lstMatches.removeAll();
   6:         GregorianCalendar gcalThis = new GregorianCalendar(nYear,0,1);
   7:         for (int nCurYear=1800; nCurYear<=2200; ++nCurYear)
   8:         ...
   9:             boolean bMatches =
  10:                 gcalThis.isLeapYear(nYear) == gcalCur.isLeapYear(nCurYear)
  11:                 &&

View Full Code Here
   1: import java.util.Calendar;
   2: import java.util.GregorianCalendar;
   3: import java.util.Locale;
   4:         ...
   5:     private CalendarCanvas canvas_;
   6:     private GregorianCalendar calendar_;
   7:     private Listener listener_ = new Listener();
   8:         ...
   9: 
  10:         GregorianCalendar calendar = new GregorianCalendar(locale);
  11:         calendar.set(year, month - 1, date);
  12:         ...
  13:     {
  14:         return calendar_.isLeapYear(getYear());

View Full Code Here

roll

public void roll(int field,
                 boolean up)
Adds or subtracts (up/down) a single unit of time on the given time field without changing larger fields.

Example: Consider a GregorianCalendar originally set to December 31, 1999. Calling roll(Calendar.MONTH, true) sets the calendar to January 31, 1999. The YEAR field is unchanged because it is a larger field than MONTH.

Overrides:
roll in interface Calendar
Parameters:
up - indicates if the value of the specified calendar field is to be rolled up or rolled down. Use true if rolling up, false otherwise.
Throws:
IllegalArgumentException - if field is ZONE_OFFSET, DST_OFFSET, or unknown, or if any calendar fields have out-of-range values in non-lenient mode.
Usages and Demos :

View More Examples of roll(int field,boolean up)
   1: 
   2:     private GregorianCalendar calendar;
   3: 
   4:         ...
   5:     public GregorianCalendarAdapter(GregorianCalendar calendar) {
   6:         this.calendar = calendar;
   7:         ...
   8:     public GregorianCalendarAdapter(int year, int month, int day) {
   9:         calendar = new GregorianCalendar(year, month, day);
  10:     }
  11:         ...
  12:     public void roll(int field, int amount) {
  13:         calendar.roll(field, amount);

View Full Code Here
   1:     protected Calendar calcDate(boolean start, int shift, int shiftUnit, int dayInShiftUnit) {
   2:         GregorianCalendar calendar = new GregorianCalendar();
   3: 
   4:         ...
   5:         if (shift != 0)
   6:             calendar.roll(shiftUnit, shift);
   7: 
   8:         if (start)
   9:             calendar.set(dayInShiftUnit, calendar.getActualMinimum(dayInShiftUnit));

View Full Code Here
   1:     {
   2:       GregorianCalendar gc = new GregorianCalendar(year_,m-1,1);
   3:       int[] daysOfMonth = new int[gc.getActualMaximum(Calendar.DAY_OF_MONTH)];
   4:         ...
   5:     daysOfMonth[i]=gc.get(Calendar.DAY_OF_WEEK);
   6:     gc.roll(Calendar.DAY_OF_WEEK,true);
   7:       }
   8:       return daysOfMonth;
   9:     }

View Full Code Here
   1: import java.util.Date;
   2: import java.util.GregorianCalendar;
   3: import java.util.List;
   4:         ...
   5:         collectFiles(dumpDirectory, filter, index);
   6:         this.startTime = new GregorianCalendar();
   7: 
   8:         ...
   9: 
  10:         GregorianCalendar estimatedCalendar = new GregorianCalendar();
  11:         estimatedCalendar.setTimeInMillis(estimatedMillis);
  12:         ...
  13:         estimatedCalendar.roll(Calendar.HOUR, false);

View Full Code Here

roll

public void roll(int field,
                 int amount)
Adds a signed amount to the specified calendar field without changing larger fields. A negative roll amount means to subtract from field without changing larger fields. If the specified amount is 0, this method performs nothing.

This method calls complete() before adding the amount so that all the calendar fields are normalized. If there is any calendar field having an out-of-range value in non-lenient mode, then an IllegalArgumentException is thrown.

Example: Consider a GregorianCalendar originally set to August 31, 1999. Calling roll(Calendar.MONTH, 8) sets the calendar to April 30, 1999. Using a GregorianCalendar, the DAY_OF_MONTH field cannot be 31 in the month April. DAY_OF_MONTH is set to the closest possible value, 30. The YEAR field maintains the value of 1999 because it is a larger field than MONTH.

Example: Consider a GregorianCalendar originally set to Sunday June 6, 1999. Calling roll(Calendar.WEEK_OF_MONTH, -1) sets the calendar to Tuesday June 1, 1999, whereas calling add(Calendar.WEEK_OF_MONTH, -1) sets the calendar to Sunday May 30, 1999. This is because the roll rule imposes an additional constraint: The MONTH must not change when the WEEK_OF_MONTH is rolled. Taken together with add rule 1, the resultant date must be between Tuesday June 1 and Saturday June 5. According to add rule 2, the DAY_OF_WEEK, an invariant when changing the WEEK_OF_MONTH, is set to Tuesday, the closest possible value to Sunday (where Sunday is the first day of the week).

Overrides:
roll in interface Calendar
Parameters:
field - the calendar field.
amount - the signed amount to add to field.
Throws:
IllegalArgumentException - if field is ZONE_OFFSET, DST_OFFSET, or unknown, or if any calendar fields have out-of-range values in non-lenient mode.
Since:
1.2
Usages and Demos :

View More Examples of roll(int field,int amount)
   1: 
   2:     private GregorianCalendar calendar;
   3: 
   4:         ...
   5:     public GregorianCalendarAdapter(GregorianCalendar calendar) {
   6:         this.calendar = calendar;
   7:         ...
   8:     public GregorianCalendarAdapter(int year, int month, int day) {
   9:         calendar = new GregorianCalendar(year, month, day);
  10:     }
  11:         ...
  12:     public void roll(int field, int amount) {
  13:         calendar.roll(field, amount);

View Full Code Here
   1:     protected Calendar calcDate(boolean start, int shift, int shiftUnit, int dayInShiftUnit) {
   2:         GregorianCalendar calendar = new GregorianCalendar();
   3: 
   4:         ...
   5:         if (shift != 0)
   6:             calendar.roll(shiftUnit, shift);
   7: 
   8:         if (start)
   9:             calendar.set(dayInShiftUnit, calendar.getActualMinimum(dayInShiftUnit));

View Full Code Here
   1:     {
   2:       GregorianCalendar gc = new GregorianCalendar(year_,m-1,1);
   3:       int[] daysOfMonth = new int[gc.getActualMaximum(Calendar.DAY_OF_MONTH)];
   4:         ...
   5:     daysOfMonth[i]=gc.get(Calendar.DAY_OF_WEEK);
   6:     gc.roll(Calendar.DAY_OF_WEEK,true);
   7:       }
   8:       return daysOfMonth;
   9:     }

View Full Code Here
   1: import java.util.Date;
   2: import java.util.GregorianCalendar;
   3: import java.util.List;
   4:         ...
   5:         collectFiles(dumpDirectory, filter, index);
   6:         this.startTime = new GregorianCalendar();
   7: 
   8:         ...
   9: 
  10:         GregorianCalendar estimatedCalendar = new GregorianCalendar();
  11:         estimatedCalendar.setTimeInMillis(estimatedMillis);
  12:         ...
  13:         estimatedCalendar.roll(Calendar.HOUR, false);

View Full Code Here

setGregorianChange

public void setGregorianChange(Date date)
Sets the GregorianCalendar change date. This is the point when the switch from Julian dates to Gregorian dates occurred. Default is October 15, 1582 (Gregorian). Previous to this, dates will be in the Julian calendar.

To obtain a pure Julian calendar, set the change date to Date(Long.MAX_VALUE). To obtain a pure Gregorian calendar, set the change date to Date(Long.MIN_VALUE).

Parameters:
date - the given Gregorian cutover date.

setTimeZone

public void setTimeZone(TimeZone zone)
Overrides:
setTimeZone in interface Calendar
Usages and Demos :

View More Examples of setTimeZone(TimeZone zone)
   1:     public void testSetYear() {
   2:         GregorianCalendar calendar = new GregorianCalendar();
   3:         calendar.set(Calendar.YEAR, 1970);
   4:         ...
   5:         calendar.set(Calendar.MILLISECOND, 0);
   6:         calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
   7: 
   8:         assertEquals(0, calendar.getTime().getTime());
   9:     }

View Full Code Here
   1: import java.util.Calendar;
   2: import java.util.GregorianCalendar;
   3: 
   4:         ...
   5: public final class CalendarParser extends AbstractCalendarParser {
   6:     public static GregorianCalendar parse( String format, String value ) throws IllegalArgumentException {
   7:         CalendarParser parser = new CalendarParser(format,value);
   8:         ...
   9:     
  10:     private final GregorianCalendar cal = new GregorianCalendar(0,0,0);
  11:     
  12:         ...
  13:     protected void setTimeZone( java.util.TimeZone tz ) {
  14:         cal.setTimeZone(tz);

View Full Code Here
   1: import java.util.Date;
   2: import java.util.GregorianCalendar;
   3: import java.util.TimeZone;
   4:         ...
   5:     private Calendar calendarFor(Date wholeDate, int dayOfYear, TimeZone timeZone) {
   6:         GregorianCalendar calendar1 = new GregorianCalendar();
   7:         ...
   8:         calendar1.setTimeZone(timeZone);
   9:         calendar1.setTime(wholeDate);
  10:         ...
  11:         calendar2.clear();
  12:         calendar2.setTimeZone(timeZone);

View Full Code Here
   1: import java.util.Calendar;
   2: import java.util.GregorianCalendar;
   3: import java.util.TimeZone;
   4:         ...
   5:         {
   6:             GregorianCalendar cal = new GregorianCalendar();
   7:             cal.clear();
   8:         ...
   9:             cal.setTimeZone(TimeZone.getTimeZone("UTC"));
  10:             cal.setTimeInMillis(millis);

View Full Code Here
   1: import java.util.Date;
   2: import java.util.GregorianCalendar;
   3: import java.util.TimeZone;
   4:         ...
   5:         SimpleDateFormat f = new SimpleDateFormat(MONTH_FORMAT);
   6:         f.setTimeZone(timeZone);
   7:         try {
   8:         ...
   9:         
  10:         GregorianCalendar c1 = new GregorianCalendar();
  11:         c1.setTime(wholeDate);
  12:         ...
  13:         c1.setTimeZone(timeZone);

View Full Code Here