Return type | Name and parameters |
---|---|
Date
|
clearTime()
Clears the time portion of this Date instance; useful utility where it makes sense to compare month/day/year only portions of a Date. |
Date
|
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(Date to, Closure closure)
Iterates from this date down to the given date, inclusive, decrementing by one day each time. |
String
|
format(String format)
Create a String representation of this date according to the given format pattern. |
String
|
format(String format, TimeZone tz)
Create a String representation of this date according to the given format pattern and timezone. |
int
|
getAt(int field)
Support the subscript operator for a Date. |
String
|
getDateString()
Return a string representation of the 'day' portion of this date according to the locale-specific DateFormat#SHORT default format. |
String
|
getDateTimeString()
Return a string representation of the date and time time portion of this Date instance, according to the locale-specific format used by DateFormat. |
String
|
getTimeString()
Return a string representation of the time portion of this date according to the locale-specific DateFormat#MEDIUM default format. |
ZoneId
|
getZoneId()
Returns the Time Zone of the Date as a ZoneId. |
ZoneOffset
|
getZoneOffset()
Returns the Time Zone offset of the Date as a ZoneOffset, which will typically be system's default offset. |
Date
|
minus(int days)
Subtract a number of days from this date and returns the new date. |
int
|
minus(Date then)
Subtract another Date from this one and return the number of days of the difference. |
Date
|
next()
Increment a Date by one day. |
Date
|
plus(int days)
Add a number of days to this date and returns the new date. |
Date
|
previous()
Decrement a Date by one day. |
void
|
putAt(int field, int value)
Support the subscript operator for mutating a Date. |
void
|
set(Map updates)
Support mutating a Date with a Map. |
Calendar
|
toCalendar()
Convert a Date to a Calendar. |
DayOfWeek
|
toDayOfWeek()
Converts the Date to a corresponding DayOfWeek. |
LocalDate
|
toLocalDate()
Converts the Date to a corresponding LocalDate. |
LocalDateTime
|
toLocalDateTime()
Converts the Date to a corresponding LocalDateTime. |
LocalTime
|
toLocalTime()
Converts the Date to a corresponding LocalTime. |
Month
|
toMonth()
Converts the Date to a corresponding Month. |
MonthDay
|
toMonthDay()
Converts the Date to a corresponding MonthDay. |
OffsetDateTime
|
toOffsetDateTime()
Converts the Date to a corresponding OffsetDateTime. |
OffsetTime
|
toOffsetTime()
Converts the Date to a corresponding OffsetTime. |
Timestamp
|
toTimestamp()
Return a java.sql.Timestamp given a java.util.Date. |
Year
|
toYear()
Converts the Date to a corresponding Year. |
YearMonth
|
toYearMonth()
Converts the Date to a corresponding YearMonth. |
ZonedDateTime
|
toZonedDateTime()
Converts the Date to a corresponding ZonedDateTime. |
Date
|
updated(Map updates)
Legacy alias for copyWith. |
void
|
upto(Date to, Closure closure)
Iterates from this date up to the given date, inclusive, incrementing by one day each time. |
addShutdownHook
, any
, any
, asBoolean
, asType
, collect
, collect
, collect
, dump
, each
, eachMatch
, eachMatch
, eachWithIndex
, every
, every
, find
, find
, findAll
, findAll
, findIndexOf
, findIndexOf
, findIndexValues
, findIndexValues
, findLastIndexOf
, findLastIndexOf
, findResult
, findResult
, getAt
, getMetaClass
, getMetaPropertyValues
, getProperties
, grep
, grep
, hasProperty
, identity
, inject
, inject
, inspect
, invokeMethod
, is
, isCase
, iterator
, metaClass
, print
, print
, printf
, printf
, println
, println
, println
, putAt
, respondsTo
, respondsTo
, setMetaClass
, split
, sprintf
, sprintf
, stream
, tap
, toString
, use
, use
, use
, with
, with
, withCloseable
, withStream
, withTraits
Clears the time portion of this Date instance; useful utility where it makes sense to compare month/day/year only portions of a Date.
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 today = new Date() def nextYear = today[YEAR] + 1 def oneYearFromNow = today.copyWith(year: nextYear) println today println oneYearFromNow
updates
- A Map of Calendar keys and valuesIterates from this date down to the given date, inclusive, decrementing by one day each time.
to
- another Date to go down toclosure
- the closure to callCreate a String representation of this date according to the given format pattern.
For example, if the system timezone is GMT,
new Date(0).format('MM/dd/yy')
would return the string
"01/01/70"
. See documentation for SimpleDateFormat
for format pattern use.
Note that a new DateFormat instance is created for every invocation of this method (for thread safety).
format
- the format pattern to use according to SimpleDateFormatCreate a String representation of this date according to the given format pattern and timezone.
For example:
def d = new Date(0)
def tz = TimeZone.getTimeZone('GMT')
println d.format('dd/MMM/yyyy', tz)
would return the string
"01/Jan/1970"
. See documentation for SimpleDateFormat
for format pattern use.
Note that a new DateFormat instance is created for every invocation of this method (for thread safety).
format
- the format pattern to use according to SimpleDateFormattz
- the TimeZone to useSupport the subscript operator for a Date.
field
- a Calendar field, e.g. MONTHReturn a string representation of the 'day' portion of this date
according to the locale-specific DateFormat#SHORT default format.
For an "en_UK" system locale, this would be dd/MM/yy
.
Note that a new DateFormat instance is created for every invocation of this method (for thread safety).
Return a string representation of the date and time time portion of this Date instance, according to the locale-specific format used by DateFormat. This method uses the DateFormat#SHORT preset for the day portion and DateFormat#MEDIUM for the time portion of the output string.
Note that a new DateFormat instance is created for every invocation of this method (for thread safety).
Return a string representation of the time portion of this date
according to the locale-specific DateFormat#MEDIUM default format.
For an "en_UK" system locale, this would be HH:MM:ss
.
Note that a new DateFormat instance is created for every invocation of this method (for thread safety).
Returns the Time Zone of the Date as a ZoneId. This will typically be the system's default ZoneId.
Returns the Time Zone offset of the Date as a ZoneOffset, which will typically be system's default offset.
Subtract a number of days from this date and returns the new date.
days
- the number of days to subtractSubtract 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 DateIncrement a Date by one day.
Add a number of days to this date and returns the new date.
days
- the number of days to increaseDecrement a Date by one day.
Support the subscript operator for mutating a Date.
field
- A Calendar field, e.g. MONTHvalue
- The value for the given field, e.g. FEBRUARYSupport mutating a Date 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.YEAR def date = new Date() def nextYear = date[YEAR] + 1 date.set(year: nextYear) println date
updates
- A Map of Calendar keys and valuesConvert a Date to a Calendar.
Converts the Date to a corresponding DayOfWeek.
Converts the Date to a corresponding LocalDate.
Converts the Date to a corresponding LocalDateTime.
Converts the Date to a corresponding LocalTime.
Converts the Date to a corresponding MonthDay.
Converts the Date to a corresponding OffsetDateTime.
Converts the Date to a corresponding OffsetTime.
Return a java.sql.Timestamp given a java.util.Date.
Converts the Date to a corresponding YearMonth.
Converts the Date to a corresponding ZonedDateTime.
Legacy alias for copyWith. Will be deprecated and removed in future versions of Groovy.