public final class DateTimeExtensions extends Object
This class defines new Groovy methods which appear on normal JDK Date/Time API (java.time) classes inside the Groovy environment. These extensions require JDK 8 or above.
Type Params | Return Type | Name and description |
---|---|---|
|
public static LocalDateTime |
clearTime(LocalDateTime self) Returns a LocalDateTime with the time portion cleared. |
|
public static OffsetDateTime |
clearTime(OffsetDateTime self) Returns an OffsetDateTime with the time portion cleared. |
|
public static ZonedDateTime |
clearTime(ZonedDateTime self) Returns an ZonedDateTime with the time portion cleared. |
|
public static Duration |
div(Duration self, long scalar) Supports the division operator; equivalent to calling the Duration.dividedBy method. |
|
public static void |
downto(Temporal from, Temporal to, Closure closure) Iterates from this to the to Temporal, inclusive, decrementing by one
unit each iteration, calling the closure once per iteration. |
|
public static void |
downto(Temporal from, Temporal to, TemporalUnit unit, Closure closure) Iterates from this to the to Temporal, inclusive, decrementing by one
unit each iteration, calling the closure once per iteration. |
|
public static String |
format(LocalDate self, String pattern) Formats this date with the provided DateTimeFormatter pattern. |
|
public static String |
format(LocalDate self, FormatStyle dateStyle) Formats this date in the provided, localized FormatStyle. |
|
public static String |
format(LocalDateTime self, String pattern) Formats this date/time with the provided DateTimeFormatter pattern. |
|
public static String |
format(LocalDateTime self, FormatStyle dateTimeStyle) Formats this date/time in the provided, localized FormatStyle. |
|
public static String |
format(LocalTime self, String pattern) Formats this time with the provided DateTimeFormatter pattern. |
|
public static String |
format(LocalTime self, FormatStyle timeStyle) Formats this time in the provided, localized FormatStyle. |
|
public static String |
format(OffsetDateTime self, String pattern) Formats this date/time with the provided DateTimeFormatter pattern. |
|
public static String |
format(OffsetDateTime self, FormatStyle dateTimeStyle) Formats this date/time in the provided, localized FormatStyle. |
|
public static String |
format(OffsetTime self, String pattern) Formats this time with the provided DateTimeFormatter pattern. |
|
public static String |
format(OffsetTime self, FormatStyle timeStyle) Formats this time in the provided, localized FormatStyle. |
|
public static String |
format(ZonedDateTime self, String pattern) Formats this date/time with the provided DateTimeFormatter pattern. |
|
public static String |
format(ZonedDateTime self, FormatStyle dateTimeStyle) Formats this date/time in the provided, localized FormatStyle. |
|
public static long |
getAt(TemporalAccessor self, TemporalField field) Supports the getAt operator; equivalent to calling the TemporalAccessor.getLong method. |
|
public static List<Long> |
getAt(TemporalAccessor self, Iterable<TemporalField> fields) Supports the getAt operator for an iterable; equivalent to collecting the TemporalAccessor.getLong method for each field in the supplied iterable. |
|
public static long |
getAt(TemporalAmount self, TemporalUnit unit) Supports the getAt operator; equivalent to calling the TemporalAmount.get method. |
|
public static long |
getAt(ZoneOffset self, TemporalField field) Supports the getAt operator; equivalent to calling the ZoneOffset.getLong method. |
|
public static String |
getDateString(LocalDate self) Formats this date with the DateTimeFormatter.ISO_LOCAL_DATE formatter. |
|
public static String |
getDateString(LocalDateTime self) Formats this date/time with the DateTimeFormatter.ISO_LOCAL_DATE formatter. |
|
public static String |
getDateString(OffsetDateTime self) Formats this date/time with the DateTimeFormatter.ISO_OFFSET_DATE formatter. |
|
public static String |
getDateString(ZonedDateTime self) Formats this date/time with the DateTimeFormatter.ISO_LOCAL_DATE formatter and appends the zone's short name, e.g. |
|
public static String |
getDateTimeString(LocalDateTime self) Formats this date/time with the DateTimeFormatter.ISO_LOCAL_DATE_TIME formatter. |
|
public static String |
getDateTimeString(OffsetDateTime self) Formats this date/time with the DateTimeFormatter.ISO_OFFSET_DATE_TIME formatter. |
|
public static String |
getDateTimeString(ZonedDateTime self) Formats this date/time with the DateTimeFormatter.ISO_LOCAL_DATE_TIME formatter and appends the zone's short name, e.g. |
|
public static int |
getEra(Year self) Equivalent to calling the Year.get method with a ChronoField.ERA argument. |
|
public static String |
getFullName(ZoneId self) Returns the name of this zone formatted according to the TextStyle.FULL text style. |
|
public static String |
getFullName(ZoneId self, Locale locale) Returns the name of this zone formatted according to the TextStyle.FULL text style for the provided Locale. |
|
public static int |
getHours(ZoneOffset self) Returns the hours component of this offset. |
|
public static int |
getMinutes(ZoneOffset self) Returns the minutes component of this offset. |
|
public static ZoneOffset |
getOffset(ZoneId self) Returns a ZoneOffset for this zone as of now. |
|
public static ZoneOffset |
getOffset(ZoneId self, Instant instant) Returns a ZoneOffset for this zone as of the provided Instant. |
|
public static int |
getSeconds(ZoneOffset self) Returns the seconds component of this offset. |
|
public static String |
getShortName(ZoneId self) Returns the name of this zone formatted according to the TextStyle.SHORT text style. |
|
public static String |
getShortName(ZoneId self, Locale locale) Returns the name of this zone formatted according to the TextStyle.SHORT text style for the provided Locale. |
|
public static String |
getTimeString(LocalDateTime self) Formats this date/time with the DateTimeFormatter.ISO_LOCAL_TIME formatter. |
|
public static String |
getTimeString(LocalTime self) Formats this time with the DateTimeFormatter.ISO_LOCAL_TIME formatter. |
|
public static String |
getTimeString(OffsetDateTime self) Formats this date/time with the DateTimeFormatter.ISO_OFFSET_TIME formatter. |
|
public static String |
getTimeString(OffsetTime self) Formats this time with the DateTimeFormatter.ISO_OFFSET_TIME formatter. |
|
public static String |
getTimeString(ZonedDateTime self) Formats this date/time with the DateTimeFormatter.ISO_LOCAL_TIME formatter and appends the zone's short name, e.g. |
|
public static int |
getYearOfEra(Year self) Equivalent to calling the Year.get method with a ChronoField.YEAR_OF_ERA argument. |
|
public static ZoneId |
getZoneId(Calendar self) Returns the Time Zone of the Calendar as a java.time.ZoneId. |
|
public static ZoneId |
getZoneId(Date self) Returns the Time Zone of the Date as a ZoneId. |
|
public static ZoneOffset |
getZoneOffset(Calendar self) Returns the Time Zone offset of the Calendar as a ZoneOffset. |
|
public static ZoneOffset |
getZoneOffset(Date self) Returns the Time Zone offset of the Date as a ZoneOffset, which will typically be system's default offset. |
|
public static boolean |
isNonnegative(Duration self) Returns true if this duration is zero or positive. |
|
public static boolean |
isNonnegative(ChronoPeriod self) Returns true if this period is zero or positive. |
|
public static boolean |
isNonpositive(Duration self) Returns true if this duration is zero or negative. |
|
public static boolean |
isNonpositive(ChronoPeriod self) Returns true if this period is zero or negative. |
|
public static boolean |
isPositive(Duration self) Returns true if this duration is positive, excluding zero. |
|
public static boolean |
isPositive(ChronoPeriod self) Returns true if this period is positive, excluding zero. |
|
public static boolean |
isWeekday(DayOfWeek self) Returns true if the DayOfWeek is a weekday. |
|
public static boolean |
isWeekend(DayOfWeek self) Returns true if this day of the week is a weekend day (Saturday or Sunday). |
|
public static LocalDateTime |
leftShift(LocalDate self, LocalTime time) Returns a LocalDateTime from this date and the provided LocalTime. |
|
public static OffsetDateTime |
leftShift(LocalDate self, OffsetTime time) Returns a OffsetDateTime from this date and the provided OffsetTime. |
|
public static OffsetDateTime |
leftShift(LocalDateTime self, ZoneOffset offset) Returns an OffsetDateTime of this date/time and the provided ZoneOffset. |
|
public static ZonedDateTime |
leftShift(LocalDateTime self, ZoneId zone) Returns a OffsetDateTime of this date/time and the provided ZoneId. |
|
public static LocalDateTime |
leftShift(LocalTime self, LocalDate date) Returns a LocalDateTime of this time and the provided LocalDate. |
|
public static OffsetTime |
leftShift(LocalTime self, ZoneOffset offset) Returns an OffsetTime of this time and the provided ZoneOffset. |
|
public static LocalDate |
leftShift(MonthDay self, int year) Returns a LocalDate of this month/day and the provided year. |
|
public static LocalDate |
leftShift(MonthDay self, Year year) Returns a LocalDate of this month/day and the provided Year. |
|
public static OffsetDateTime |
leftShift(OffsetTime self, LocalDate date) Returns an OffsetDateTime of this time and the provided LocalDate. |
|
public static YearMonth |
leftShift(Year self, Month month) Returns a YearMonth of this year and the provided Month. |
|
public static LocalDate |
leftShift(Year self, MonthDay monthDay) Returns a LocalDate of this year on the given MonthDay. |
|
public static LocalDate |
leftShift(YearMonth self, int dayOfMonth) Returns a LocalDate of this year/month and the given day of the month. |
|
public static ZonedDateTime |
leftShift(ZoneId self, LocalDateTime dateTime) Returns a ZonedDateTime of this zone and the given LocalDateTime. |
|
public static OffsetDateTime |
leftShift(ZoneOffset self, LocalDateTime dateTime) Returns an OffsetDateTime of this offset and the provided LocalDateTime. |
|
public static OffsetTime |
leftShift(ZoneOffset self, LocalTime time) Returns an OffsetDateTime of this offset and the provided LocalTime. |
|
public static MonthDay |
leftShift(Month self, int dayOfMonth) Creates a MonthDay at the provided day of the month. |
|
public static YearMonth |
leftShift(Month self, Year year) Creates a YearMonth at the provided Year. |
|
public static Duration |
minus(Duration self, long seconds) Returns a Duration that is seconds seconds shorter that this duration. |
|
public static Instant |
minus(Instant self, long seconds) Returns an Instant that is seconds seconds before this instant. |
|
public static LocalDate |
minus(LocalDate self, long days) Returns a LocalDate that is days days before this date. |
|
public static long |
minus(LocalDate self, LocalDate other) Calculates the number of days between two dates |
|
public static LocalDateTime |
minus(LocalDateTime self, long seconds) Returns a LocalDateTime that is seconds seconds before this date/time. |
|
public static LocalTime |
minus(LocalTime self, long seconds) Returns a LocalTime that is seconds seconds before this time. |
|
public static OffsetDateTime |
minus(OffsetDateTime self, long seconds) Returns an OffsetDateTime that is seconds seconds before this date/time. |
|
public static OffsetTime |
minus(OffsetTime self, long seconds) Returns an OffsetTime that is seconds seconds before this time. |
|
public static Period |
minus(Period self, long days) Returns a Period that is days days shorter than this period.
|
|
public static Year |
minus(Year self, long years) Returns a Year that is years years before this year. |
|
public static YearMonth |
minus(YearMonth self, long months) Returns a YearMonth that is months months before this year/month. |
|
public static ZonedDateTime |
minus(ZonedDateTime self, long seconds) Returns a ZonedDateTime that is seconds seconds before this date/time. |
|
public static DayOfWeek |
minus(DayOfWeek self, int days) Returns the DayOfWeek that is days many days before this day of the week. |
|
public static Month |
minus(Month self, int months) Returns the Month that is months months before this month. |
|
public static Duration |
multiply(Duration self, long scalar) Supports the multiplication operator; equivalent to calling the Duration.multipliedBy method. |
|
public static Period |
multiply(Period self, int scalar) Supports the multiply operator; equivalent to calling the Period.multipliedBy method. |
|
public static Duration |
negative(Duration self) Supports the unary minus operator; equivalent to calling the Duration.negated method. |
|
public static Period |
negative(Period self) Supports the unary minus operator; equivalent to calling the Period.negated method. |
|
public static Duration |
next(Duration self) Returns a Duration that is one second longer than this duration. |
|
public static Instant |
next(Instant self) Returns an Instant that is one second after this instant. |
|
public static LocalDate |
next(LocalDate self) Returns a LocalDate one day after this date. |
|
public static LocalDateTime |
next(LocalDateTime self) Returns a LocalDateTime that is one second after this date/time. |
|
public static LocalTime |
next(LocalTime self) Returns a LocalTime that is one second after this time. |
|
public static OffsetDateTime |
next(OffsetDateTime self) Returns an OffsetDateTime one second after this date/time. |
|
public static OffsetTime |
next(OffsetTime self) Returns an OffsetTime that is one second after this time. |
|
public static Period |
next(Period self) Returns a Period that is one day longer than this period. |
|
public static Year |
next(Year self) Returns a Year after this year. |
|
public static YearMonth |
next(YearMonth self) Returns a YearMonth that is the month after this year/month. |
|
public static ZonedDateTime |
next(ZonedDateTime self) Returns a ZonedDateTime that is one second after this date/time. |
|
public static Duration |
plus(Duration self, long seconds) Returns a Duration that is seconds seconds longer than this duration. |
|
public static Instant |
plus(Instant self, long seconds) Returns an Instant that is seconds seconds after this instant. |
|
public static LocalDate |
plus(LocalDate self, long days) Returns a LocalDate that is days days after this date. |
|
public static LocalDateTime |
plus(LocalDateTime self, long seconds) Returns a LocalDateTime that is seconds seconds after this date/time. |
|
public static LocalTime |
plus(LocalTime self, long seconds) Returns a LocalTime that is seconds seconds after this time. |
|
public static OffsetDateTime |
plus(OffsetDateTime self, long seconds) Returns an OffsetDateTime that is seconds seconds after this date/time. |
|
public static OffsetTime |
plus(OffsetTime self, long seconds) Returns an OffsetTime that is seconds seconds after this time. |
|
public static Period |
plus(Period self, long days) Returns a Period that is days days longer than this period.
|
|
public static Year |
plus(Year self, long years) Returns a Year that is years years after this year. |
|
public static YearMonth |
plus(YearMonth self, long months) Returns a YearMonth that is months months after this year/month. |
|
public static ZonedDateTime |
plus(ZonedDateTime self, long seconds) Returns a ZonedDateTime that is seconds seconds after this date/time. |
|
public static DayOfWeek |
plus(DayOfWeek self, int days) Returns the DayOfWeek that is days many days after this day of the week. |
|
public static Month |
plus(Month self, int months) Returns the Month that is months months after this month. |
|
public static Duration |
positive(Duration self) Supports the unary plus operator; equivalent to calling the Duration.abs method. |
|
public static Period |
positive(Period self) Supports the unary plus operator; returns a Period with all unit values positive. |
|
public static Duration |
previous(Duration self) Returns a Duration that is one second shorter than this duration. |
|
public static Instant |
previous(Instant self) Returns an Instant that one second before this instant. |
|
public static LocalDate |
previous(LocalDate self) Returns a LocalDate one day before this date. |
|
public static LocalDateTime |
previous(LocalDateTime self) Returns a LocalDateTime that is one second before this date/time. |
|
public static LocalTime |
previous(LocalTime self) Returns a LocalTime that is one second before this time. |
|
public static OffsetDateTime |
previous(OffsetDateTime self) Returns an OffsetDateTime one second before this date/time. |
|
public static OffsetTime |
previous(OffsetTime self) Returns an OffsetTime that is one second before this time. |
|
public static Period |
previous(Period self) Returns a Period that is one day shorter than this period. |
|
public static Year |
previous(Year self) Returns a Year before this year. |
|
public static YearMonth |
previous(YearMonth self) Returns a YearMonth that is the month before this year/month. |
|
public static ZonedDateTime |
previous(ZonedDateTime self) Returns a ZonedDateTime that is one second before this date/time. |
|
public static TemporalAmount |
rightShift(Temporal self, Temporal other) Returns a Duration or Period between this (inclusive) and the other
Temporal (exclusive). |
|
public static Period |
rightShift(LocalDate self, LocalDate other) Returns a Period equivalent to the time between this date (inclusive) and the provided LocalDate (exclusive). |
|
public static Period |
rightShift(Year self, Year year) Returns a Period between the first day of this year (inclusive) and the first day of the provided Year (exclusive). |
|
public static Period |
rightShift(YearMonth self, YearMonth other) Returns a Period of time between the first day of this year/month (inclusive) and the given YearMonth (exclusive). |
|
public static Calendar |
toCalendar(Instant self) Returns a generally equivalent Calendar in the GMT time zone, truncated to milliseconds. |
|
public static Calendar |
toCalendar(LocalDate self) Returns an equivalent instance of Calendar. |
|
public static Calendar |
toCalendar(LocalDateTime self) Returns a generally equivalent instance of Calendar. |
|
public static Calendar |
toCalendar(LocalTime self) Returns a generally equivalent instance of Calendar. |
|
public static Calendar |
toCalendar(OffsetDateTime self) Returns a generally equivalent instance of Calendar. |
|
public static Calendar |
toCalendar(OffsetTime self) Returns a generally equivalent instance of Calendar. |
|
public static Calendar |
toCalendar(ZonedDateTime self) Returns a generally equivalent instance of Calendar. |
|
public static Date |
toDate(Instant self) Returns a generally equivalent Date according the number of milliseconds since the epoch, adjusted into the system default time zone. |
|
public static Date |
toDate(LocalDate self) Returns an equivalent instance of Date. |
|
public static Date |
toDate(LocalDateTime self) Returns a generally equivalent instance of Date. |
|
public static Date |
toDate(LocalTime self) Returns a generally equivalent instance of Date. |
|
public static Date |
toDate(OffsetDateTime self) Returns a generally equivalent instance of Date. |
|
public static Date |
toDate(OffsetTime self) Returns a generally equivalent instance of Date. |
|
public static Date |
toDate(ZonedDateTime self) Returns a generally equivalent instance of Date. |
|
public static DayOfWeek |
toDayOfWeek(Calendar self) Converts the Calendar to a corresponding DayOfWeek. |
|
public static DayOfWeek |
toDayOfWeek(Date self) Converts the Date to a corresponding DayOfWeek. |
|
public static Instant |
toInstant(Calendar self) Convenience method for converting a Calendar to a corresponding Instant. |
|
public static LocalDate |
toLocalDate(Date self) Converts the Date to a corresponding LocalDate. |
|
public static LocalDateTime |
toLocalDateTime(Calendar self) Converts the Calendar to a corresponding LocalDateTime. |
|
public static LocalDateTime |
toLocalDateTime(Date self) Converts the Date to a corresponding LocalDateTime. |
|
public static LocalTime |
toLocalTime(Calendar self) Converts the Calendar to a corresponding LocalTime. |
|
public static LocalTime |
toLocalTime(Date self) Converts the Date to a corresponding LocalTime. |
|
public static Month |
toMonth(Calendar self) Converts the Calendar to a corresponding Month. |
|
public static Month |
toMonth(Date self) Converts the Date to a corresponding Month. |
|
public static MonthDay |
toMonthDay(Calendar self) Converts the Calendar to a corresponding MonthDay. |
|
public static MonthDay |
toMonthDay(Date self) Converts the Date to a corresponding MonthDay. |
|
public static OffsetDateTime |
toOffsetDateTime(Calendar self) Converts the Calendar to a corresponding OffsetDateTime. |
|
public static OffsetDateTime |
toOffsetDateTime(Date self) Converts the Date to a corresponding OffsetDateTime. |
|
public static OffsetTime |
toOffsetTime(Calendar self) Converts the Calendar to a corresponding OffsetTime. |
|
public static OffsetTime |
toOffsetTime(Date self) Converts the Date to a corresponding OffsetTime. |
|
public static TimeZone |
toTimeZone(ZoneId self) Returns a TimeZone equivalent to this zone. |
|
public static TimeZone |
toTimeZone(ZoneOffset self) Returns a generally equivalent TimeZone. |
|
public static Year |
toYear(Calendar self) Converts the Calendar to a corresponding Year. |
|
public static Year |
toYear(Date self) Converts the Date to a corresponding Year. |
|
public static YearMonth |
toYearMonth(Calendar self) Converts the Calendar to a corresponding YearMonth. |
|
public static YearMonth |
toYearMonth(Date self) Converts the Date to a corresponding YearMonth. |
|
public static ZoneOffset |
toZoneOffset(TimeZone self) Converts the TimeZone to a corresponding ZoneOffset. |
|
public static ZoneOffset |
toZoneOffset(TimeZone self, Instant instant) Converts this TimeZone to a corresponding ZoneOffset. |
|
public static ZonedDateTime |
toZonedDateTime(Calendar self) |
|
public static ZonedDateTime |
toZonedDateTime(Date self) Converts the Date to a corresponding ZonedDateTime. |
|
public static void |
upto(Temporal from, Temporal to, Closure closure) Iterates from this to the to Temporal, inclusive, incrementing by one
unit each iteration, calling the closure once per iteration. |
|
public static void |
upto(Temporal from, Temporal to, TemporalUnit unit, Closure closure) Iterates from this to the to Temporal, inclusive, incrementing by one
unit each iteration, calling the closure once per iteration. |
Returns a LocalDateTime with the time portion cleared.
self
- a LocalDateTimeReturns an OffsetDateTime with the time portion cleared.
self
- an OffsetDateTimeReturns an ZonedDateTime with the time portion cleared.
self
- a ZonedDateTimeSupports the division operator; equivalent to calling the Duration.dividedBy method.
self
- a Durationscalar
- the value to divide by Iterates from this to the to
Temporal, inclusive, decrementing by one
unit each iteration, calling the closure once per iteration. The closure may accept a single
Temporal argument.
The particular unit decremented by depends on the specific subtype of Temporal. Most subtypes use a unit of ChronoUnit.SECONDS except for
to
to
is a different type than thisfrom
- the starting Temporalto
- the ending Temporalclosure
- the zero or one-argument closure to call Iterates from this to the to
Temporal, inclusive, decrementing by one
unit
each iteration, calling the closure once per iteration. The closure may accept a single
Temporal argument.
If the unit is too large to iterate to the second Temporal exactly, such as iterating from two LocalDateTimes
that are seconds apart using ChronoUnit.DAYS as the unit, the iteration will cease
as soon as the current value of the iteration is earlier than the second Temporal argument. The closure will
not be called with any value earlier than the to
value.
to
to
is a different type than thisfrom
- the starting Temporalto
- the ending Temporalunit
- the TemporalUnit to increment byclosure
- the zero or one-argument closure to callFormats this date with the provided DateTimeFormatter pattern.
self
- a LocalDatepattern
- the formatting patternFormats this date in the provided, localized FormatStyle.
self
- a LocalDatedateStyle
- the FormatStyleFormats this date/time with the provided DateTimeFormatter pattern.
self
- a LocalDateTimepattern
- the formatting patternFormats this date/time in the provided, localized FormatStyle.
self
- a LocalDateTimedateTimeStyle
- the FormatStyleFormats this time with the provided DateTimeFormatter pattern.
self
- a LocalDateTimepattern
- the formatting patternFormats this time in the provided, localized FormatStyle.
self
- a LocalTimetimeStyle
- the FormatStyleFormats this date/time with the provided DateTimeFormatter pattern.
self
- an OffsetDateTimepattern
- the formatting patternFormats this date/time in the provided, localized FormatStyle.
self
- an OffsetDateTimedateTimeStyle
- the FormatStyleFormats this time with the provided DateTimeFormatter pattern.
self
- an OffsetTimepattern
- the formatting patternFormats this time in the provided, localized FormatStyle.
self
- an OffsetTimetimeStyle
- the FormatStyleFormats this date/time with the provided DateTimeFormatter pattern.
self
- a ZonedDateTimepattern
- the formatting patternFormats this date/time in the provided, localized FormatStyle.
self
- a ZonedDateTimedateTimeStyle
- the FormatStyleSupports the getAt operator; equivalent to calling the TemporalAccessor.getLong method.
self
- a TemporalAccessorfield
- a non-null TemporalFieldSupports the getAt operator for an iterable; equivalent to collecting the TemporalAccessor.getLong method for each field in the supplied iterable.
import static java.time.temporal.ChronoField.* import java.time.LocalTime def breakfast = LocalTime.of(8, 30, 0) def (h, m, s) = breakfast[HOUR_OF_DAY, MINUTE_OF_HOUR, SECOND_OF_MINUTE] assert "$h:$m:$s" == "8:30:0"
self
- a TemporalAccessorfields
- an iterable of non-null TemporalField valuesSupports the getAt operator; equivalent to calling the TemporalAmount.get method.
self
- a TemporalAmountunit
- a non-null TemporalUnitSupports the getAt operator; equivalent to calling the ZoneOffset.getLong method.
self
- a ZoneOffsetfield
- a TemporalFieldFormats this date with the DateTimeFormatter.ISO_LOCAL_DATE formatter.
self
- a LocalDateFormats this date/time with the DateTimeFormatter.ISO_LOCAL_DATE formatter.
self
- a LocalDateTimeFormats this date/time with the DateTimeFormatter.ISO_OFFSET_DATE formatter.
self
- an OffsetDateTime Formats this date/time with the DateTimeFormatter.ISO_LOCAL_DATE formatter
and appends the zone's short name, e.g. 2018-03-10EST
.
self
- a ZonedDateTimeFormats this date/time with the DateTimeFormatter.ISO_LOCAL_DATE_TIME formatter.
self
- a LocalDateTimeFormats this date/time with the DateTimeFormatter.ISO_OFFSET_DATE_TIME formatter.
self
- an OffsetDateTime Formats this date/time with the DateTimeFormatter.ISO_LOCAL_DATE_TIME formatter
and appends the zone's short name, e.g. 2018-03-10T14:34:55.144EST
.
self
- a ZonedDateTimeEquivalent to calling the Year.get method with a ChronoField.ERA argument.
Returns the era of the year, which is currently either 0 (BC) or 1 (AD).
self
- a YearReturns the name of this zone formatted according to the TextStyle.FULL text style.
self
- a ZoneIdReturns the name of this zone formatted according to the TextStyle.FULL text style for the provided Locale.
self
- a ZoneIdlocale
- a LocaleReturns the hours component of this offset. If the offset's total seconds are negative, a negative value will be returned.
self
- a ZoneOffsetReturns the minutes component of this offset. If the offset's total seconds are negative, a negative value will be returned.
self
- a ZoneOffsetReturns a ZoneOffset for this zone as of now.
self
- a ZoneIdReturns a ZoneOffset for this zone as of the provided Instant.
self
- a ZoneIdinstant
- an InstantReturns the seconds component of this offset. This is not the same as the total seconds. For example:
def offset = ZoneOffset.ofHoursMinutesSeconds(0, 1, 1) assert offset.seconds == 1 assert offset.totalSeconds == 61
If the offset's total seconds are negative, a negative value will be returned.
self
- a ZoneOffsetReturns the name of this zone formatted according to the TextStyle.SHORT text style.
self
- a ZoneIdReturns the name of this zone formatted according to the TextStyle.SHORT text style for the provided Locale.
self
- a ZoneIdlocale
- a LocaleFormats this date/time with the DateTimeFormatter.ISO_LOCAL_TIME formatter.
self
- a LocalDateTimeFormats this time with the DateTimeFormatter.ISO_LOCAL_TIME formatter.
self
- a LocalTimeFormats this date/time with the DateTimeFormatter.ISO_OFFSET_TIME formatter.
self
- an OffsetDateTimeFormats this time with the DateTimeFormatter.ISO_OFFSET_TIME formatter.
self
- an OffsetTime Formats this date/time with the DateTimeFormatter.ISO_LOCAL_TIME formatter
and appends the zone's short name, e.g. 14:34:55.144EST
.
self
- a ZonedDateTimeEquivalent to calling the Year.get method with a ChronoField.YEAR_OF_ERA argument.
Since Year=0 represents 1 BC, the yearOfEra value of Year=0 is 1, Year=-1 is 2, and so on.
self
- a YearReturns the Time Zone of the Calendar as a java.time.ZoneId.
self
- a CalendarReturns the Time Zone of the Date as a ZoneId. This will typically be the system's default ZoneId.
self
- a DateReturns the Time Zone offset of the Calendar as a ZoneOffset.
self
- a CalendarReturns the Time Zone offset of the Date as a ZoneOffset, which will typically be system's default offset.
self
- a DateReturns true if this duration is zero or positive.
self
- a DurationReturns true if this period is zero or positive.
self
- a ChronoPeriodReturns true if this duration is zero or negative.
self
- a DurationReturns true if this period is zero or negative.
self
- a ChronoPeriodReturns true if this duration is positive, excluding zero.
self
- a DurationReturns true if this period is positive, excluding zero.
self
- a ChronoPeriod Returns true
if the DayOfWeek is a weekday.
Returns true
if this day of the week is a weekend day (Saturday or Sunday).
self
- a DayOfWeekReturns a LocalDateTime from this date and the provided LocalTime.
self
- a LocalDatetime
- a LocalTimeReturns a OffsetDateTime from this date and the provided OffsetTime.
self
- a LocalDatetime
- an OffsetTimeReturns an OffsetDateTime of this date/time and the provided ZoneOffset.
self
- a LocalDateTimeoffset
- a ZoneOffsetReturns a OffsetDateTime of this date/time and the provided ZoneId.
self
- a LocalDateTimezone
- a ZoneIdReturns a LocalDateTime of this time and the provided LocalDate.
self
- a LocalTimedate
- a LocalDateReturns an OffsetTime of this time and the provided ZoneOffset.
self
- a LocalTimeoffset
- a ZoneOffsetReturns a LocalDate of this month/day and the provided year.
self
- a MonthDayyear
- a yearReturns a LocalDate of this month/day and the provided Year.
self
- a MonthDayyear
- a YearReturns an OffsetDateTime of this time and the provided LocalDate.
self
- an OffsetTimedate
- a LocalDateReturns a YearMonth of this year and the provided Month.
self
- a Yearmonth
- a MonthReturns a LocalDate of this year on the given MonthDay.
self
- a YearmonthDay
- a MonthDayReturns a LocalDate of this year/month and the given day of the month.
self
- a YearMonthdayOfMonth
- a day of the monthReturns a ZonedDateTime of this zone and the given LocalDateTime.
self
- a ZoneIdReturns an OffsetDateTime of this offset and the provided LocalDateTime.
self
- a ZoneOffsetdateTime
- a LocalDateTimeReturns an OffsetDateTime of this offset and the provided LocalTime.
self
- a ZoneOffsettime
- a LocalTimeCreates a MonthDay at the provided day of the month.
self
- a MonthdayOfMonth
- a day of the monthCreates a YearMonth at the provided Year.
self
- a Monthyear
- a Year Returns a Duration that is seconds
seconds shorter that this duration.
self
- a Durationseconds
- the number of seconds to subtract Returns an Instant that is seconds
seconds before this instant.
self
- an Instantseconds
- the number of seconds to subtract Returns a LocalDate that is days
days before this date.
self
- a LocalDatedays
- the number of days to subtractCalculates the number of days between two dates
self
- a LocalDateother
- the other LocalDate Returns a LocalDateTime that is seconds
seconds before this date/time.
self
- a LocalDateTimeseconds
- the number of seconds to subtract Returns a LocalTime that is seconds
seconds before this time.
self
- a LocalTimeseconds
- the number of seconds to subtract Returns an OffsetDateTime that is seconds
seconds before this date/time.
self
- an OffsetDateTimeseconds
- the number of seconds to subtract Returns an OffsetTime that is seconds
seconds before this time.
self
- an OffsetTimeseconds
- the number of seconds to subtract Returns a Period that is days
days shorter than this period.
No normalization is performed.
self
- a Perioddays
- the number of days to decrease this Period by Returns a Year that is years
years before this year.
self
- a Yearyears
- the number of years to subtract Returns a YearMonth that is months
months before this year/month.
self
- a YearMonthmonths
- the number of months to subtract Returns a ZonedDateTime that is seconds
seconds before this date/time.
self
- a ZonedDateTimeseconds
- the number of seconds to subtract Returns the DayOfWeek that is days
many days before this day of the week.
self
- a DayOfWeekdays
- the number of days to move back Returns the Month that is months
months before this month.
self
- a Monthmonths
- the number of months to move backSupports the multiplication operator; equivalent to calling the Duration.multipliedBy method.
self
- a Durationscalar
- the value to multiply bySupports the multiply operator; equivalent to calling the Period.multipliedBy method.
self
- a Periodscalar
- a scalar to multiply each unit bySupports the unary minus operator; equivalent to calling the Duration.negated method.
self
- a DurationSupports the unary minus operator; equivalent to calling the Period.negated method.
self
- a PeriodReturns a Duration that is one second longer than this duration.
self
- a DurationReturns an Instant that is one second after this instant.
self
- an InstantReturns a LocalDate one day after this date.
self
- a LocalDateReturns a LocalDateTime that is one second after this date/time.
self
- a LocalDateTimeReturns a LocalTime that is one second after this time.
self
- a LocalTimeReturns an OffsetDateTime one second after this date/time.
self
- an OffsetDateTimeReturns an OffsetTime that is one second after this time.
self
- an OffsetTimeReturns a Period that is one day longer than this period. No normalization is performed.
self
- a PeriodReturns a Year after this year.
self
- a YearReturns a YearMonth that is the month after this year/month.
self
- a YearMonthReturns a ZonedDateTime that is one second after this date/time.
self
- a ZonedDateTime Returns a Duration that is seconds
seconds longer than this duration.
self
- a Durationseconds
- the number of seconds to add Returns an Instant that is seconds
seconds after this instant.
self
- an Instantseconds
- the number of seconds to add Returns a LocalDate that is days
days after this date.
self
- a LocalDatedays
- the number of days to add Returns a LocalDateTime that is seconds
seconds after this date/time.
self
- a LocalDateTimeseconds
- the number of seconds to add Returns a LocalTime that is seconds
seconds after this time.
self
- a LocalTimeseconds
- the number of seconds to add Returns an OffsetDateTime that is seconds
seconds after this date/time.
self
- an OffsetDateTimeseconds
- the number of seconds to add Returns an OffsetTime that is seconds
seconds after this time.
self
- an OffsetTimeseconds
- the number of seconds to add Returns a Period that is days
days longer than this period.
No normalization is performed.
self
- a Perioddays
- the number of days to increase this Period by Returns a Year that is years
years after this year.
self
- a Yearyears
- the number of years to add Returns a YearMonth that is months
months after this year/month.
self
- a YearMonthmonths
- the number of months to add Returns a ZonedDateTime that is seconds
seconds after this date/time.
self
- an ZonedDateTimeseconds
- the number of seconds to add Returns the DayOfWeek that is days
many days after this day of the week.
self
- a DayOfWeekdays
- the number of days to move forward Returns the Month that is months
months after this month.
self
- a Monthmonths
- the number of months move forwardSupports the unary plus operator; equivalent to calling the Duration.abs method.
self
- a DurationSupports the unary plus operator; returns a Period with all unit values positive. For example, a period of "2 years, -3 months, and -4 days" would result in a period of "2 years, 3 months, and 4 days." No normalization is performed.
self
- a PeriodReturns a Duration that is one second shorter than this duration.
self
- a DurationReturns an Instant that one second before this instant.
self
- an InstantReturns a LocalDate one day before this date.
self
- a LocalDateReturns a LocalDateTime that is one second before this date/time.
self
- a LocalDateTimeReturns a LocalTime that is one second before this time.
self
- a LocalTimeReturns an OffsetDateTime one second before this date/time.
self
- an OffsetDateTimeReturns an OffsetTime that is one second before this time.
self
- an OffsetTimeReturns a Period that is one day shorter than this period. No normalization is performed.
self
- a PeriodReturns a Year before this year.
self
- a YearReturns a YearMonth that is the month before this year/month.
self
- a YearMonthReturns a ZonedDateTime that is one second before this date/time.
self
- a ZonedDateTime Returns a Duration or Period between this (inclusive) and the other
Temporal (exclusive).
A Period will be returned for types Year, YearMonth, and ChronoLocalDate; otherwise, a Duration will be returned.
Note: if the Temporal is a ChronoLocalDate but not a LocalDate, a general ChronoPeriod will be returned as per the return type of the method ChronoLocalDate.until .
self
- a Temporalother
- another Temporal of the same typeReturns a Period equivalent to the time between this date (inclusive) and the provided LocalDate (exclusive).
self
- a LocalDateother
- another LocalDateReturns a Period between the first day of this year (inclusive) and the first day of the provided Year (exclusive).
self
- a Yearyear
- another YearReturns a Period of time between the first day of this year/month (inclusive) and the given YearMonth (exclusive).
self
- a YearMonthother
- another YearMonthReturns a generally equivalent Calendar in the GMT time zone, truncated to milliseconds.
self
- an InstantReturns an equivalent instance of Calendar. The time portion of the returned calendar is cleared and the time zone is the current system default.
self
- a LocalDateReturns a generally equivalent instance of Calendar. The time value of the returned calendar is truncated to milliseconds and the time zone is the current system default.
self
- a LocalDateTimeReturns a generally equivalent instance of Calendar. The day-month-year value of the returned calendar is today, the time is truncated to milliseconds, and the time zone is the current system default.
self
- a LocalTimeReturns a generally equivalent instance of Calendar. The time value of the returned calendar is truncated to milliseconds and the time zone is based on the offset of this date/time.
self
- an OffsetDateTimeReturns a generally equivalent instance of Calendar. The date value of the returned calendar is now, the time value is truncated to milliseconds, and the time zone is based on the offset of this time.
self
- an OffsetTimeReturns a generally equivalent instance of Calendar. The time value of the returned calendar is truncated to milliseconds and the time zone is determined by the zone of this date/time.
self
- an ZonedDateTimeReturns a generally equivalent Date according the number of milliseconds since the epoch, adjusted into the system default time zone.
self
- an InstantReturns an equivalent instance of Date. The time portion of the returned date is cleared.
self
- a LocalDateReturns a generally equivalent instance of Date. The time value of the returned date is truncated to milliseconds.
self
- a LocalDateTimeReturns a generally equivalent instance of Date. The day-month-year value of the returned date is today and the time is truncated to milliseconds.
self
- a LocalTimeReturns a generally equivalent instance of Date. The time value of the returned date is truncated to milliseconds and will be adjusted to the current system default time zone.
self
- an OffsetDateTimeReturns a generally equivalent instance of Date. The time value of the returned date is truncated to milliseconds and will be adjusted to the current system default time zone.
self
- an OffsetTimeReturns a generally equivalent instance of Date. The time value of the returned date is truncated to milliseconds and will be adjusted to the current system default time zone.
self
- a ZonedDateTimeConverts 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.
self
- a CalendarConverts the Date to a corresponding DayOfWeek.
self
- a DateConvenience method for converting a Calendar to a corresponding Instant.
self
- a CalendarConverts the Date to a corresponding LocalDate.
self
- a DateConverts 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.
self
- a CalendarConverts the Date to a corresponding LocalDateTime.
self
- a DateConverts 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.
self
- a CalendarConverts the Date to a corresponding LocalTime.
self
- a DateConverts 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.
self
- a CalendarConverts the Date to a corresponding Month.
self
- a DateConverts 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.
self
- a CalendarConverts the Date to a corresponding MonthDay.
self
- a DateConverts the Calendar to a corresponding OffsetDateTime.
self
- a CalendarConverts the Date to a corresponding OffsetDateTime.
self
- a DateConverts the Calendar to a corresponding OffsetTime.
self
- a CalendarConverts the Date to a corresponding OffsetTime.
self
- a DateReturns a TimeZone equivalent to this zone.
self
- a ZoneIdReturns a generally equivalent TimeZone. The offset will be truncated to minutes.
self
- a ZoneOffsetConverts 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.
self
- a CalendarConverts the Date to a corresponding Year.
self
- a DateConverts 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.
self
- a CalendarConverts the Date to a corresponding YearMonth.
self
- a DateConverts the TimeZone to a corresponding ZoneOffset. The offset is determined using the current date/time.
self
- a TimeZoneConverts this TimeZone to a corresponding ZoneOffset. The offset is determined using the date/time of specified Instant.
self
- a TimeZone
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.
self
- a CalendarConverts the Date to a corresponding ZonedDateTime.
self
- a Date Iterates from this to the to
Temporal, inclusive, incrementing by one
unit each iteration, calling the closure once per iteration. The closure may accept a single
Temporal argument.
The particular unit incremented by depends on the specific subtype of Temporal. Most subtypes use a unit of ChronoUnit.SECONDS except for
to
to
is a different type than thisfrom
- the starting Temporalto
- the ending Temporalclosure
- the zero or one-argument closure to call Iterates from this to the to
Temporal, inclusive, incrementing by one
unit
each iteration, calling the closure once per iteration. The closure may accept a single
Temporal argument.
If the unit is too large to iterate to the second Temporal exactly, such as iterating from two LocalDateTimes
that are seconds apart using ChronoUnit.DAYS as the unit, the iteration will cease
as soon as the current value of the iteration is later than the second Temporal argument. The closure will
not be called with any value later than the to
value.
to
to
is a different type than thisfrom
- the starting Temporalto
- the ending Temporalunit
- the TemporalUnit to increment byclosure
- the zero or one-argument closure to call