Class Calendar

Represents a Calendar and is based on the java.util.Calendar class. Refer to the java.util.Calendar documentation for more information.

IMPORTANT NOTE: Please use the StringUtils.formatCalendar(Calendar) functions to convert a Calendar object into a String.

ConstantDescription
AM_PM: Number = 9Indicates whether the HOUR is before or after noon.
APRIL: Number = 3Value for the month of year field representing April.
AUGUST: Number = 7Value for the month of year field representing August.
DATE: Number = 5Represents a date.
DAY_OF_MONTH: Number = 5Represents a day of the month.
DAY_OF_WEEK: Number = 7Represents a day of the week.
DAY_OF_WEEK_IN_MONTH: Number = 8Represents a day of the week in a month.
DAY_OF_YEAR: Number = 6Represents a day of the year.
DECEMBER: Number = 11Value for the month of year field representing December.
DST_OFFSET: Number = 16Indicates the daylight savings offset in milliseconds.
ERA: Number = 0Indicates the era such as 'AD' or 'BC' in the Julian calendar.
FEBRUARY: Number = 1Value for the month of year field representing February.
FRIDAY: Number = 6Value for the day of the week field representing Friday.
HOUR: Number = 10Represents an hour.
HOUR_OF_DAY: Number = 11Represents an hour of the day.
INPUT_DATE_PATTERN: Number = 3The input date pattern, for instance MM/dd/yyyy
INPUT_DATE_TIME_PATTERN: Number = 5The input date time pattern, for instance MM/dd/yyyy h a
INPUT_TIME_PATTERN: Number = 4The input time pattern, for instance h a
JANUARY: Number = 0Value for the month of year field representing January.
JULY: Number = 6Value for the month of year field representing July.
JUNE: Number = 5Value for the month of year field representing June.
LONG_DATE_PATTERN: Number = 1The long date pattern, for instance MMM/d/yyyy
MARCH: Number = 2Value for the month of year field representing March.
MAY: Number = 4Value for the month of year field representing May.
MILLISECOND: Number = 14Represents a millisecond.
MINUTE: Number = 12Represents a minute.
MONDAY: Number = 2Value for the day of the week field representing Monday.
MONTH: Number = 2Represents a month where the first month of the year is 0.
NOVEMBER: Number = 10Value for the month of year field representing November.
OCTOBER: Number = 9Value for the month of year field representing October.
SATURDAY: Number = 7Value for the day of the week field representing Saturday.
SECOND: Number = 13Represents a second.
SEPTEMBER: Number = 8Value for the month of year field representing September.
SHORT_DATE_PATTERN: Number = 0The short date pattern, for instance M/d/yy
SUNDAY: Number = 1Value for the day of the week field representing Sunday.
THURSDAY: Number = 5Value for the day of the week field representing Thursday.
TIME_PATTERN: Number = 2The time pattern, for instance h:mm a
TUESDAY: Number = 3Value for the day of the week field representing Tuesday.
WEDNESDAY: Number = 4Value for the day of the week field representing Wednesday.
WEEK_OF_MONTH: Number = 4Represents a week of the month.
WEEK_OF_YEAR: Number = 3Represents a week in the year.
YEAR: Number = 1Represents a year.
ZONE_OFFSET: Number = 15Indicates the raw offset from GMT in milliseconds.
PropertyDescription
firstDayOfWeek: NumberReturns the first day of the week base on locale context.
time: DateReturns the current time stamp of this calendar.
timeZone: StringReturns the current time zone of this calendar.
ConstructorDescription
Calendar()Creates a new Calendar object that is set to the current time.
Calendar(Date)Creates a new Calendar object for the given Date object.
MethodDescription
add(Number, Number)Adds or subtracts the specified amount of time to the given calendar field, based on the calendar's rules.
after(Object)Indicates if this Calendar represents a time after the time represented by the specified Object.
before(Object)Indicates if this Calendar represents a time before the time represented by the specified Object.
clear()Sets all the calendar field values and the time value (millisecond offset from the Epoch) of this Calendar undefined.
clear(Number)Sets the given calendar field value and the time value (millisecond offset from the Epoch) of this Calendar undefined.
compareTo(Calendar)Compares the time values (millisecond offsets from the Epoch) represented by two Calendar objects.
equals(Object)Compares two calendar values whether they are equivalent.
get(Number)Returns the value of the given calendar field.
getActualMaximum(Number)Returns the maximum value that the specified calendar field could have.
getActualMinimum(Number)Returns the minimum value that the specified calendar field could have.
getFirstDayOfWeek()Returns the first day of the week base on locale context.
getMaximum(Number)Returns the maximum value for the given calendar field.
getMinimum(Number)Returns the minimum value for the given calendar field.
getTime()Returns the current time stamp of this calendar.
getTimeZone()Returns the current time zone of this calendar.
hashCode()Calculates the hash code for a calendar;
isLeapYear(Number)Indicates if the specified year is a leap year.
isSameDay(Calendar)Checks, whether two calendar dates fall on the same day.
isSameDayByTimestamp(Calendar)Checks, whether two calendar dates fall on the same day.
isSet(Number)Indicates if the field is set.
parseByFormat(String, String)Parses the string according to the date and time format pattern and set the time at this calendar object.
parseByLocale(String, String, Number)Parses the string according the date format pattern of the given locale.
roll(Number, Boolean)Rolls the specified field up or down one value.
roll(Number, Number)Rolls the specified field using the specified value.
set(Number, Number)Sets the given calendar field to the given value.
set(Number, Number, Number)Sets the values for the calendar fields YEAR, MONTH, and DAY_OF_MONTH.
set(Number, Number, Number, Number, Number)Sets the values for the calendar fields YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, and MINUTE.
set(Number, Number, Number, Number, Number, Number)Sets the values for the calendar fields YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, MINUTE and SECOND.
setFirstDayOfWeek(Number)Sets what the first day of the week is.
setTime(Date)Sets the current time stamp of this calendar.

WARNING: Keep in mind that the set Date object's time is always interpreted in the time zone GMT.
setTimeZone(String)Sets the current time zone of this calendar.

WARNING: Keep in mind that the time stamp represented by the calendar is always interpreted in the time zone GMT.

assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values

AM_PM: Number = 9

Indicates whether the HOUR is before or after noon.


APRIL: Number = 3

Value for the month of year field representing April.


AUGUST: Number = 7

Value for the month of year field representing August.


DATE: Number = 5

Represents a date.


DAY_OF_MONTH: Number = 5

Represents a day of the month.


DAY_OF_WEEK: Number = 7

Represents a day of the week.


DAY_OF_WEEK_IN_MONTH: Number = 8

Represents a day of the week in a month.


DAY_OF_YEAR: Number = 6

Represents a day of the year.


DECEMBER: Number = 11

Value for the month of year field representing December.


DST_OFFSET: Number = 16

Indicates the daylight savings offset in milliseconds.


ERA: Number = 0

Indicates the era such as 'AD' or 'BC' in the Julian calendar.


FEBRUARY: Number = 1

Value for the month of year field representing February.


FRIDAY: Number = 6

Value for the day of the week field representing Friday.


HOUR: Number = 10

Represents an hour.


HOUR_OF_DAY: Number = 11

Represents an hour of the day.


INPUT_DATE_PATTERN: Number = 3

The input date pattern, for instance MM/dd/yyyy


INPUT_DATE_TIME_PATTERN: Number = 5

The input date time pattern, for instance MM/dd/yyyy h a


INPUT_TIME_PATTERN: Number = 4

The input time pattern, for instance h a


JANUARY: Number = 0

Value for the month of year field representing January.


JULY: Number = 6

Value for the month of year field representing July.


JUNE: Number = 5

Value for the month of year field representing June.


LONG_DATE_PATTERN: Number = 1

The long date pattern, for instance MMM/d/yyyy


MARCH: Number = 2

Value for the month of year field representing March.


MAY: Number = 4

Value for the month of year field representing May.


MILLISECOND: Number = 14

Represents a millisecond.


MINUTE: Number = 12

Represents a minute.


MONDAY: Number = 2

Value for the day of the week field representing Monday.


MONTH: Number = 2

Represents a month where the first month of the year is 0.


NOVEMBER: Number = 10

Value for the month of year field representing November.


OCTOBER: Number = 9

Value for the month of year field representing October.


SATURDAY: Number = 7

Value for the day of the week field representing Saturday.


SECOND: Number = 13

Represents a second.


SEPTEMBER: Number = 8

Value for the month of year field representing September.


SHORT_DATE_PATTERN: Number = 0

The short date pattern, for instance M/d/yy


SUNDAY: Number = 1

Value for the day of the week field representing Sunday.


THURSDAY: Number = 5

Value for the day of the week field representing Thursday.


TIME_PATTERN: Number = 2

The time pattern, for instance h:mm a


TUESDAY: Number = 3

Value for the day of the week field representing Tuesday.


WEDNESDAY: Number = 4

Value for the day of the week field representing Wednesday.


WEEK_OF_MONTH: Number = 4

Represents a week of the month.


WEEK_OF_YEAR: Number = 3

Represents a week in the year.


YEAR: Number = 1

Represents a year.


ZONE_OFFSET: Number = 15

Indicates the raw offset from GMT in milliseconds.


firstDayOfWeek: Number

Returns the first day of the week base on locale context. For example, in the US the first day of the week is SUNDAY. However, in France the first day of the week is MONDAY.


time: Date

Returns the current time stamp of this calendar. This method is also used to convert a Calendar into a Date.

WARNING: Keep in mind that the returned Date object's time is always interpreted in the time zone GMT. This means time zone information set at the calendar object will not be honored and gets lost.


timeZone: String

Returns the current time zone of this calendar.


Calendar()

Creates a new Calendar object that is set to the current time. The default time zone of the Calendar object is GMT.

WARNING: Keep in mind that the time stamp represented by the new calendar is always interpreted in the time zone GMT. This means time zone information at the calendar object needs to be set separately by using the setTimeZone(String) method.


Calendar(date: Date)

Creates a new Calendar object for the given Date object. The time is set to the given Date object's time. The default time zone of the Calendar object is GMT.

WARNING: Keep in mind that the given Date object is always interpreted in the time zone GMT. This means time zone information at the calendar object needs to be set separately by using the setTimeZone(String) method.

Parameters:

  • date - the date for which the calendar will be set.

add(field: Number, value: Number): void

Adds or subtracts the specified amount of time to the given calendar field, based on the calendar's rules.

Parameters:

  • field - the calendar field.
  • value - the amount of date or time to be added to the field

after(obj: Object): Boolean

Indicates if this Calendar represents a time after the time represented by the specified Object.

Parameters:

  • obj - the object to test.

Returns:

  • true if this Calendar represents a time after the time represented by the specified Object, false otherwise.

before(obj: Object): Boolean

Indicates if this Calendar represents a time before the time represented by the specified Object.

Parameters:

  • obj - the object to test.

Returns:

  • true if this Calendar represents a time before the time represented by the specified Object, false otherwise.

clear(): void

Sets all the calendar field values and the time value (millisecond offset from the Epoch) of this Calendar undefined.


clear(field: Number): void

Sets the given calendar field value and the time value (millisecond offset from the Epoch) of this Calendar undefined.

Parameters:

  • field - the calendar field to be cleared.

compareTo(anotherCalendar: Calendar): Number

Compares the time values (millisecond offsets from the Epoch) represented by two Calendar objects.

Parameters:

  • anotherCalendar - the Calendar to be compared.

Returns:

  • the value 0 if the time represented by the argument is equal to the time represented by this Calendar; a value less than 0 if the time of this Calendar is before the time represented by the argument; and a value greater than 0 if the time of this Calendar is after the time represented by the argument.

equals(other: Object): Boolean

Compares two calendar values whether they are equivalent.

Parameters:

  • other - the object to compare against this calendar.

get(field: Number): Number

Returns the value of the given calendar field.

Parameters:

  • field - the calendar field to retrieve.

Returns:

  • the value for the given calendar field.

getActualMaximum(field: Number): Number

Returns the maximum value that the specified calendar field could have.

Parameters:

  • field - the calendar field.

Returns:

  • the maximum value that the specified calendar field could have.

getActualMinimum(field: Number): Number

Returns the minimum value that the specified calendar field could have.

Parameters:

  • field - the calendar field.

Returns:

  • the minimum value that the specified calendar field could have.

getFirstDayOfWeek(): Number

Returns the first day of the week base on locale context. For example, in the US the first day of the week is SUNDAY. However, in France the first day of the week is MONDAY.

Returns:

  • the first day of the week base on locale context. For example, in the US the first day of the week is SUNDAY. However, in France the first day of the week is MONDAY.

getMaximum(field: Number): Number

Returns the maximum value for the given calendar field.

Parameters:

  • field - the calendar field.

Returns:

  • the maximum value for the given calendar field.

getMinimum(field: Number): Number

Returns the minimum value for the given calendar field.

Parameters:

  • field - the calendar field.

Returns:

  • the minimum value for the given calendar field.

getTime(): Date

Returns the current time stamp of this calendar. This method is also used to convert a Calendar into a Date.

WARNING: Keep in mind that the returned Date object's time is always interpreted in the time zone GMT. This means time zone information set at the calendar object will not be honored and gets lost.

Returns:

  • the current time stamp of this calendar as a Date.

getTimeZone(): String

Returns the current time zone of this calendar.

Returns:

  • the current time zone of this calendar.

hashCode(): Number

Calculates the hash code for a calendar;


isLeapYear(year: Number): Boolean

Indicates if the specified year is a leap year.

Parameters:

  • year - the year to test.

Returns:

  • true if the specified year is a leap year.

isSameDay(other: Calendar): Boolean

Checks, whether two calendar dates fall on the same day.

The method performs comparison based on both calendar's field values by honoring the defined time zones.

Examples:

would return true.

would return false.

would return false.

would return false since the time zone is applied first which results in comparing 2002/02/28 01:00 for cal1 with 2002/02/27 23:00 for cal2.

Parameters:

  • other - the calendar to compare against this calendar.

isSameDayByTimestamp(other: Calendar): Boolean

Checks, whether two calendar dates fall on the same day.

The method performs comparison based on both calendar's time stamps by ignoring any defined time zones.

Examples:

would return true.

would return false.

would return false.

would return true since the time zone is not applied first which results in comparing 2002/02/28 02:00 for cal1 with 2002/02/28 00:00 for cal2.

Parameters:

  • other - the calendar to compare against this calendar.

isSet(field: Number): Boolean

Indicates if the field is set.

Parameters:

  • field - the field to test.

Returns:

  • true if the field is set, false otherwise.

parseByFormat(timeString: String, format: String): void

Parses the string according to the date and time format pattern and set the time at this calendar object. For the specification of the date and time format pattern see the javadoc of the JDK class java.text.SimpleDateFormat. If a time zone is included in the format string, this time zone is used to interpet the time. Otherwise the currently set calendar time zone is used to parse the given time string.

Parameters:

  • timeString - the time string to parsed
  • format - the time format string

parseByLocale(timeString: String, locale: String, pattern: Number): void

Parses the string according the date format pattern of the given locale. If the locale name is invalid, an exception is thrown. The currently set calendar time zone is used to parse the given time string.

Parameters:

  • timeString - the time string to parsed
  • locale - the locale id, which defines the date format pattern
  • pattern - the pattern is one of calendar pattern e.g. SHORT_DATE_PATTERN as defined in the regional settings for the locale

roll(field: Number, up: Boolean): void

Rolls the specified field up or down one value.

Parameters:

  • field - the field to roll.
  • up - if true rolls the field up, if false rolls the field down.

roll(field: Number, amount: Number): void

Rolls the specified field using the specified value.

Parameters:

  • field - the field to roll.
  • amount - the amount to roll the field.

set(field: Number, value: Number): void

Sets the given calendar field to the given value.

Parameters:

  • field - the calendar field to set.
  • value - the value to set in the field.

set(year: Number, month: Number, date: Number): void

Sets the values for the calendar fields YEAR, MONTH, and DAY_OF_MONTH.

Parameters:

  • year - the value for year.
  • month - the value for month.
  • date - the value for date.

set(year: Number, month: Number, date: Number, hourOfDay: Number, minute: Number): void

Sets the values for the calendar fields YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, and MINUTE.

Parameters:

  • year - the value for year.
  • month - the value for month.
  • date - the value for date.
  • hourOfDay - the value for hour of day.
  • minute - the value for minute.

set(year: Number, month: Number, date: Number, hourOfDay: Number, minute: Number, second: Number): void

Sets the values for the calendar fields YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, MINUTE and SECOND.

Parameters:

  • year - the value for year.
  • month - the value for month.
  • date - the value for date.
  • hourOfDay - the value for hour of day.
  • minute - the value for minute.
  • second - the value for second.

setFirstDayOfWeek(value: Number): void

Sets what the first day of the week is.

Parameters:

  • value - the day to set as the first day of the week.

setTime(date: Date): void

Sets the current time stamp of this calendar.

WARNING: Keep in mind that the set Date object's time is always interpreted in the time zone GMT. This means that time zone information at the calendar object needs to be set separately by using the setTimeZone(String) method.

Parameters:

  • date - the current time stamp of this calendar.

setTimeZone(timeZone: String): void

Sets the current time zone of this calendar.

WARNING: Keep in mind that the time stamp represented by the calendar is always interpreted in the time zone GMT. Changing the time zone will not change the calendar's time stamp.

Parameters:

  • timeZone - the current time zone value to set.