Return type | Name and parameters |
---|---|
Calendar
|
clearTime()
Clears the time portion of this Calendar instance; useful utility where it makes sense to compare month/day/year only portions of a Calendar. |
Calendar
|
copyWith(Map updates)
Support creating a new Date having similar properties to an existing Date (which remains unaltered) but with some fields updated according to a Map of changes. |
void
|
downto(Calendar to, Closure closure)
Iterates from the date represented by this calendar up to the date represented by the given calendar, inclusive, incrementing by one day each time. |
String
|
format(String pattern)
Shortcut for SimpleDateFormat to output a String representation of this calendar instance. |
int
|
getAt(int field)
Support the subscript operator for a Calendar. |
ZoneId
|
getZoneId()
Returns the Time Zone of the Calendar as a java.time.ZoneId. |
ZoneOffset
|
getZoneOffset()
Returns the Time Zone offset of the Calendar as a ZoneOffset. |
int
|
minus(Calendar then)
Subtract another date from this one and return the number of days of the difference. |
Calendar
|
next()
Increment a Calendar by one day. |
Calendar
|
previous()
Decrement a Calendar by one day. |
void
|
putAt(int field, int value)
Support the subscript operator for mutating a Calendar. |
void
|
set(Map updates)
Support mutating a Calendar with a Map. |
DayOfWeek
|
toDayOfWeek()
Converts the Calendar to a corresponding DayOfWeek. |
Instant
|
toInstant()
Convenience method for converting a Calendar to a corresponding Instant. |
LocalDateTime
|
toLocalDateTime()
Converts the Calendar to a corresponding LocalDateTime. |
LocalTime
|
toLocalTime()
Converts the Calendar to a corresponding LocalTime. |
Month
|
toMonth()
Converts the Calendar to a corresponding Month. |
MonthDay
|
toMonthDay()
Converts the Calendar to a corresponding MonthDay. |
OffsetDateTime
|
toOffsetDateTime()
Converts the Calendar to a corresponding OffsetDateTime. |
OffsetTime
|
toOffsetTime()
Converts the Calendar to a corresponding OffsetTime. |
Year
|
toYear()
Converts the Calendar to a corresponding Year. |
YearMonth
|
toYearMonth()
Converts the Calendar to a corresponding YearMonth. |
ZonedDateTime
|
toZonedDateTime()
Converts the Calendar to a corresponding ZonedDateTime. |
Calendar
|
updated(Map updates)
Legacy alias for copyWith. |
void
|
upto(Calendar to, Closure closure)
Iterates from the date represented by this calendar up to the date represented by the given calendar, inclusive, incrementing by one day each time. |
addShutdownHook
, any
, any
, asBoolean
, asType
, average
, collect
, collect
, collect
, contains
, count
, dump
, each
, eachWithIndex
, equals
, every
, every
, find
, find
, findAll
, findAll
, findIndexOf
, findIndexOf
, findIndexValues
, findIndexValues
, findLastIndexOf
, findLastIndexOf
, findResult
, findResult
, flatten
, getAt
, getMetaClass
, getMetaPropertyValues
, getProperties
, grep
, grep
, groupBy
, groupBy
, hasProperty
, identity
, inject
, inject
, inspect
, invokeMethod
, is
, isCase
, iterator
, join
, metaClass
, print
, print
, printf
, printf
, println
, println
, println
, putAt
, respondsTo
, respondsTo
, setMetaClass
, size
, split
, sprintf
, sprintf
, stream
, sum
, sum
, tap
, toArrayString
, toSpreadMap
, toString
, use
, use
, use
, with
, with
, withTraits
Clears the time portion of this Calendar instance; useful utility where it makes sense to compare month/day/year only portions of a Calendar.
Support creating a new Date having similar properties to an existing Date (which remains unaltered) but with some fields updated according to a Map of changes.
Example usage:
import static java.util.Calendar.YEAR def now = Calendar.instance def nextYear = now[YEAR] + 1 def oneYearFromNow = now.copyWith(year: nextYear) println now.time println oneYearFromNow.time
updates
- A Map of Calendar keys and valuesIterates from the date represented by this calendar up to the date represented by the given calendar, inclusive, incrementing by one day each time.
to
- another Calendar to go down toclosure
- the closure to callShortcut for SimpleDateFormat to output a String representation
of this calendar instance. This method respects the Calendar's assigned
TimeZone, whereas calling cal.time.format('HH:mm:ss')
would use the system timezone.
Note that Calendar equivalents of date.getDateString()
and variants do not exist because those methods are Locale-dependent.
Although a Calendar may be assigned a Locale, that information is
lost and therefore cannot be used to control the default date/time formats
provided by these methods. Instead, the system Locale would always be
used. The alternative is to simply call
DateFormat#getDateInstance(int, java.util.Locale) and pass the same Locale
that was used for the Calendar.
pattern
- format patternSupport the subscript operator for a Calendar.
field
- a Calendar field, e.g. MONTHReturns the Time Zone of the Calendar as a java.time.ZoneId.
Returns the Time Zone offset of the Calendar as a ZoneOffset.
Subtract another date from this one and return the number of days of the difference.
Date self = Date then + (Date self - Date then)
IOW, if self is before then the result is a negative value.
then
- another CalendarIncrement a Calendar by one day.
Decrement a Calendar by one day.
Support the subscript operator for mutating a Calendar. Example usage:
import static java.util.Calendar.* def cal = Calendar.instance cal[DAY_OF_WEEK] = MONDAY cal[MONTH] = MARCH println cal.time // A Monday in March
field
- A Calendar field, e.g. MONTHvalue
- The value for the given field, e.g. FEBRUARYSupport mutating a Calendar with a Map.
The map values are the normal values provided as the
second parameter to java.util.Calendar#set(int, int)
.
The keys can either be the normal fields values provided as
the first parameter to that method or one of the following Strings:
year | Calendar.YEAR |
month | Calendar.MONTH |
date | Calendar.DATE |
dayOfMonth | Calendar.DATE |
hourOfDay | Calendar.HOUR_OF_DAY |
minute | Calendar.MINUTE |
second | Calendar.SECOND |
import static java.util.Calendar.* def cal = Calendar.instance def m = [:] m[YEAR] = 2010 m[MONTH] = DECEMBER m[DATE] = 25 cal.set(m) println cal.time // Christmas 2010 cal.set(year:2011, month:DECEMBER, date:25) println cal.time // Christmas 2010
updates
- A Map of Calendar keys and valuesConverts the Calendar to a corresponding DayOfWeek. If the Calendar has a different time zone than the system default, the DayOfWeek will be adjusted into the default time zone.
Convenience method for converting a Calendar to a corresponding Instant.
Converts the Calendar to a corresponding LocalDateTime. If the Calendar has a different time zone than the system default, the LocalDateTime will be adjusted into the default time zone.
Converts the Calendar to a corresponding LocalTime. If the Calendar has a different time zone than the system default, the LocalTime will be adjusted into the default time zone.
Converts the Calendar to a corresponding Month. If the Calendar has a different time zone than the system default, the Month will be adjusted into the default time zone.
Converts the Calendar to a corresponding MonthDay. If the Calendar has a different time zone than the system default, the MonthDay will be adjusted into the default time zone.
Converts the Calendar to a corresponding OffsetDateTime.
Converts the Calendar to a corresponding OffsetTime.
Converts the Calendar to a corresponding Year. If the Calendar has a different time zone than the system default, the Year will be adjusted into the default time zone.
Converts the Calendar to a corresponding YearMonth. If the Calendar has a different time zone than the system default, the YearMonth will be adjusted into the default time zone.
Converts the Calendar to a corresponding ZonedDateTime.
Note that GregorianCalendar has a GregorianCalendar#toZonedDateTime method, which is commonly the specific type of Calendar in use.
Legacy alias for copyWith. Will be deprecated and removed in future versions of Groovy.