[Java] Class DateTimeExtensions

  • org.apache.groovy.datetime.extensions.DateTimeExtensions

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.

Methods Summary

Methods
Type Params Return Type Name and description
static LocalDateTime clearTime(LocalDateTime self)
Returns a LocalDateTime with the time portion cleared.
static OffsetDateTime clearTime(OffsetDateTime self)
Returns an OffsetDateTime with the time portion cleared.
static ZonedDateTime clearTime(ZonedDateTime self)
Returns an ZonedDateTime with the time portion cleared.
static Duration div(Duration self, long scalar)
Supports the division operator; equivalent to calling the Duration.dividedBy method.
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.
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.
static String format(LocalDate self, String pattern)
Formats this date with the provided DateTimeFormatter pattern.
static String format(LocalDate self, FormatStyle dateStyle)
Formats this date in the provided, localized FormatStyle.
static String format(LocalDateTime self, String pattern)
Formats this date/time with the provided DateTimeFormatter pattern.
static String format(LocalDateTime self, FormatStyle dateTimeStyle)
Formats this date/time in the provided, localized FormatStyle.
static String format(LocalTime self, String pattern)
Formats this time with the provided DateTimeFormatter pattern.
static String format(LocalTime self, FormatStyle timeStyle)
Formats this time in the provided, localized FormatStyle.
static String format(OffsetDateTime self, String pattern)
Formats this date/time with the provided DateTimeFormatter pattern.
static String format(OffsetDateTime self, FormatStyle dateTimeStyle)
Formats this date/time in the provided, localized FormatStyle.
static String format(OffsetTime self, String pattern)
Formats this time with the provided DateTimeFormatter pattern.
static String format(OffsetTime self, FormatStyle timeStyle)
Formats this time in the provided, localized FormatStyle.
static String format(ZonedDateTime self, String pattern)
Formats this date/time with the provided DateTimeFormatter pattern.
static String format(ZonedDateTime self, FormatStyle dateTimeStyle)
Formats this date/time in the provided, localized FormatStyle.
static long getAt(TemporalAccessor self, TemporalField field)
Supports the getAt operator; equivalent to calling the TemporalAccessor.getLong method.
static long getAt(TemporalAmount self, TemporalUnit unit)
Supports the getAt operator; equivalent to calling the TemporalAmount.get method.
static long getAt(ZoneOffset self, TemporalField field)
Supports the getAt operator; equivalent to calling the ZoneOffset.getLong method.
static String getDateString(LocalDate self)
Formats this date with the DateTimeFormatter.ISO_LOCAL_DATE formatter.
static String getDateString(LocalDateTime self)
Formats this date/time with the DateTimeFormatter.ISO_LOCAL_DATE formatter.
static String getDateString(OffsetDateTime self)
Formats this date/time with the DateTimeFormatter.ISO_OFFSET_DATE formatter.
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.
static String getDateTimeString(LocalDateTime self)
Formats this date/time with the DateTimeFormatter.ISO_LOCAL_DATE_TIME formatter.
static String getDateTimeString(OffsetDateTime self)
Formats this date/time with the DateTimeFormatter.ISO_OFFSET_DATE_TIME formatter.
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.
static int getEra(Year self)
Equivalent to calling the Year.get method with a ChronoField.ERA argument.
static String getFullName(ZoneId self)
Returns the name of this zone formatted according to the TextStyle.FULL text style.
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.
static int getHours(ZoneOffset self)
Returns the hours component of this offset.
static int getMinutes(ZoneOffset self)
Returns the minutes component of this offset.
static ZoneOffset getOffset(ZoneId self)
Returns a ZoneOffset for this zone as of now.
static ZoneOffset getOffset(ZoneId self, Instant instant)
Returns a ZoneOffset for this zone as of the provided Instant.
static int getSeconds(ZoneOffset self)
Returns the seconds component of this offset.
static String getShortName(ZoneId self)
Returns the name of this zone formatted according to the TextStyle.SHORT text style.
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.
static String getTimeString(LocalDateTime self)
Formats this date/time with the DateTimeFormatter.ISO_LOCAL_TIME formatter.
static String getTimeString(LocalTime self)
Formats this time with the DateTimeFormatter.ISO_LOCAL_TIME formatter.
static String getTimeString(OffsetDateTime self)
Formats this date/time with the DateTimeFormatter.ISO_OFFSET_TIME formatter.
static String getTimeString(OffsetTime self)
Formats this time with the DateTimeFormatter.ISO_OFFSET_TIME formatter.
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.
static int getYearOfEra(Year self)
Equivalent to calling the Year.get method with a ChronoField.YEAR_OF_ERA argument.
static ZoneId getZoneId(Calendar self)
Returns the Time Zone of the Calendar as a java.time.ZoneId.
static ZoneId getZoneId(Date self)
Returns the Time Zone of the Date as a ZoneId.
static ZoneOffset getZoneOffset(Calendar self)
Returns the Time Zone offset of the Calendar as a ZoneOffset.
static ZoneOffset getZoneOffset(Date self)
Returns the Time Zone offset of the Date as a ZoneOffset, which will typically be system's default offset.
static boolean isNonnegative(Duration self)
Returns true if this duration is zero or positive.
static boolean isNonnegative(ChronoPeriod self)
Returns true if this period is zero or positive.
static boolean isNonpositive(Duration self)
Returns true if this duration is zero or negative.
static boolean isNonpositive(ChronoPeriod self)
Returns true if this period is zero or negative.
static boolean isPositive(Duration self)
Returns true if this duration is positive, excluding zero.
static boolean isPositive(ChronoPeriod self)
Returns true if this period is positive, excluding zero.
static boolean isWeekday(DayOfWeek self)
Returns true if the DayOfWeek is a weekday.
static boolean isWeekend(DayOfWeek self)
Returns true if this day of the week is a weekend day (Saturday or Sunday).
static LocalDateTime leftShift(LocalDate self, LocalTime time)
Returns a LocalDateTime from this date and the provided LocalTime.
static OffsetDateTime leftShift(LocalDate self, OffsetTime time)
Returns a OffsetDateTime from this date and the provided OffsetTime.
static OffsetDateTime leftShift(LocalDateTime self, ZoneOffset offset)
Returns an OffsetDateTime of this date/time and the provided ZoneOffset.
static ZonedDateTime leftShift(LocalDateTime self, ZoneId zone)
Returns a OffsetDateTime of this date/time and the provided ZoneId.
static LocalDateTime leftShift(LocalTime self, LocalDate date)
Returns a LocalDateTime of this time and the provided LocalDate.
static OffsetTime leftShift(LocalTime self, ZoneOffset offset)
Returns an OffsetTime of this time and the provided ZoneOffset.
static LocalDate leftShift(MonthDay self, int year)
Returns a LocalDate of this month/day and the provided year.
static LocalDate leftShift(MonthDay self, Year year)
Returns a LocalDate of this month/day and the provided Year.
static OffsetDateTime leftShift(OffsetTime self, LocalDate date)
Returns an OffsetDateTime of this time and the provided LocalDate.
static YearMonth leftShift(Year self, Month month)
Returns a YearMonth of this year and the provided Month.
static LocalDate leftShift(Year self, MonthDay monthDay)
Returns a LocalDate of this year on the given MonthDay.
static LocalDate leftShift(YearMonth self, int dayOfMonth)
Returns a LocalDate of this year/month and the given day of the month.
static ZonedDateTime leftShift(ZoneId self, LocalDateTime dateTime)
Returns a ZonedDateTime of this zone and the given LocalDateTime.
static OffsetDateTime leftShift(ZoneOffset self, LocalDateTime dateTime)
Returns an OffsetDateTime of this offset and the provided LocalDateTime.
static OffsetTime leftShift(ZoneOffset self, LocalTime time)
Returns an OffsetDateTime of this offset and the provided LocalTime.
static MonthDay leftShift(Month self, int dayOfMonth)
Creates a MonthDay at the provided day of the month.
static YearMonth leftShift(Month self, Year year)
Creates a YearMonth at the provided Year.
static Duration minus(Duration self, long seconds)
Returns a Duration that is seconds seconds shorter that this duration.
static Instant minus(Instant self, long seconds)
Returns an Instant that is seconds seconds before this instant.
static LocalDate minus(LocalDate self, long days)
Returns a LocalDate that is days days before this date.
static long minus(LocalDate self, LocalDate other)
Calculates the number of days between two dates
static LocalDateTime minus(LocalDateTime self, long seconds)
Returns a LocalDateTime that is seconds seconds before this date/time.
static LocalTime minus(LocalTime self, long seconds)
Returns a LocalTime that is seconds seconds before this time.
static OffsetDateTime minus(OffsetDateTime self, long seconds)
Returns an OffsetDateTime that is seconds seconds before this date/time.
static OffsetTime minus(OffsetTime self, long seconds)
Returns an OffsetTime that is seconds seconds before this time.
static Period minus(Period self, long days)
Returns a Period that is days days shorter than this period.
static Year minus(Year self, long years)
Returns a Year that is years years before this year.
static YearMonth minus(YearMonth self, long months)
Returns a YearMonth that is months months before this year/month.
static ZonedDateTime minus(ZonedDateTime self, long seconds)
Returns a ZonedDateTime that is seconds seconds before this date/time.
static DayOfWeek minus(DayOfWeek self, int days)
Returns the DayOfWeek that is days many days before this day of the week.
static Month minus(Month self, int months)
Returns the Month that is months months before this month.
static Duration multiply(Duration self, long scalar)
Supports the multiplication operator; equivalent to calling the Duration.multipliedBy method.
static Period multiply(Period self, int scalar)
Supports the multiply operator; equivalent to calling the Period.multipliedBy method.
static Duration negative(Duration self)
Supports the unary minus operator; equivalent to calling the Duration.negated method.
static Period negative(Period self)
Supports the unary minus operator; equivalent to calling the Period.negated method.
static Duration next(Duration self)
Returns a Duration that is one second longer than this duration.
static Instant next(Instant self)
Returns an Instant that is one second after this instant.
static LocalDate next(LocalDate self)
Returns a LocalDate one day after this date.
static LocalDateTime next(LocalDateTime self)
Returns a LocalDateTime that is one second after this date/time.
static LocalTime next(LocalTime self)
Returns a LocalTime that is one second after this time.
static OffsetDateTime next(OffsetDateTime self)
Returns an OffsetDateTime one second after this date/time.
static OffsetTime next(OffsetTime self)
Returns an OffsetTime that is one second after this time.
static Period next(Period self)
Returns a Period that is one day longer than this period.
static Year next(Year self)
Returns a Year after this year.
static YearMonth next(YearMonth self)
Returns a YearMonth that is the month after this year/month.
static ZonedDateTime next(ZonedDateTime self)
Returns a ZonedDateTime that is one second after this date/time.
static Duration plus(Duration self, long seconds)
Returns a Duration that is seconds seconds longer than this duration.
static Instant plus(Instant self, long seconds)
Returns an Instant that is seconds seconds after this instant.
static LocalDate plus(LocalDate self, long days)
Returns a LocalDate that is days days after this date.
static LocalDateTime plus(LocalDateTime self, long seconds)
Returns a LocalDateTime that is seconds seconds after this date/time.
static LocalTime plus(LocalTime self, long seconds)
Returns a LocalTime that is seconds seconds after this time.
static OffsetDateTime plus(OffsetDateTime self, long seconds)
Returns an OffsetDateTime that is seconds seconds after this date/time.
static OffsetTime plus(OffsetTime self, long seconds)
Returns an OffsetTime that is seconds seconds after this time.
static Period plus(Period self, long days)
Returns a Period that is days days longer than this period.
static Year plus(Year self, long years)
Returns a Year that is years years after this year.
static YearMonth plus(YearMonth self, long months)
Returns a YearMonth that is months months after this year/month.
static ZonedDateTime plus(ZonedDateTime self, long seconds)
Returns a ZonedDateTime that is seconds seconds after this date/time.
static DayOfWeek plus(DayOfWeek self, int days)
Returns the DayOfWeek that is days many days after this day of the week.
static Month plus(Month self, int months)
Returns the Month that is months months after this month.
static Duration positive(Duration self)
Supports the unary plus operator; equivalent to calling the Duration.abs method.
static Period positive(Period self)
Supports the unary plus operator; returns a Period with all unit values positive.
static Duration previous(Duration self)
Returns a Duration that is one second shorter than this duration.
static Instant previous(Instant self)
Returns an Instant that one second before this instant.
static LocalDate previous(LocalDate self)
Returns a LocalDate one day before this date.
static LocalDateTime previous(LocalDateTime self)
Returns a LocalDateTime that is one second before this date/time.
static LocalTime previous(LocalTime self)
Returns a LocalTime that is one second before this time.
static OffsetDateTime previous(OffsetDateTime self)
Returns an OffsetDateTime one second before this date/time.
static OffsetTime previous(OffsetTime self)
Returns an OffsetTime that is one second before this time.
static Period previous(Period self)
Returns a Period that is one day shorter than this period.
static Year previous(Year self)
Returns a Year before this year.
static YearMonth previous(YearMonth self)
Returns a YearMonth that is the month before this year/month.
static ZonedDateTime previous(ZonedDateTime self)
Returns a ZonedDateTime that is one second before this date/time.
static TemporalAmount rightShift(Temporal self, Temporal other)
Returns a Duration or Period between this (inclusive) and the other Temporal (exclusive).
static Period rightShift(LocalDate self, LocalDate other)
Returns a Period equivalent to the time between this date (inclusive) and the provided LocalDate (exclusive).
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).
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).
static Calendar toCalendar(Instant self)
Returns a generally equivalent Calendar in the GMT time zone, truncated to milliseconds.
static Calendar toCalendar(LocalDate self)
Returns an equivalent instance of Calendar.
static Calendar toCalendar(LocalDateTime self)
Returns a generally equivalent instance of Calendar.
static Calendar toCalendar(LocalTime self)
Returns a generally equivalent instance of Calendar.
static Calendar toCalendar(OffsetDateTime self)
Returns a generally equivalent instance of Calendar.
static Calendar toCalendar(OffsetTime self)
Returns a generally equivalent instance of Calendar.
static Calendar toCalendar(ZonedDateTime self)
Returns a generally equivalent instance of Calendar.
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.
static Date toDate(LocalDate self)
Returns an equivalent instance of Date.
static Date toDate(LocalDateTime self)
Returns a generally equivalent instance of Date.
static Date toDate(LocalTime self)
Returns a generally equivalent instance of Date.
static Date toDate(OffsetDateTime self)
Returns a generally equivalent instance of Date.
static Date toDate(OffsetTime self)
Returns a generally equivalent instance of Date.
static Date toDate(ZonedDateTime self)
Returns a generally equivalent instance of Date.
static DayOfWeek toDayOfWeek(Calendar self)
Converts the Calendar to a corresponding DayOfWeek.
static DayOfWeek toDayOfWeek(Date self)
Converts the Date to a corresponding DayOfWeek.
static Instant toInstant(Calendar self)
Convenience method for converting a Calendar to a corresponding Instant.
static LocalDate toLocalDate(Date self)
Converts the Date to a corresponding LocalDate.
static LocalDateTime toLocalDateTime(Calendar self)
Converts the Calendar to a corresponding LocalDateTime.
static LocalDateTime toLocalDateTime(Date self)
Converts the Date to a corresponding LocalDateTime.
static LocalTime toLocalTime(Calendar self)
Converts the Calendar to a corresponding LocalTime.
static LocalTime toLocalTime(Date self)
Converts the Date to a corresponding LocalTime.
static Month toMonth(Calendar self)
Converts the Calendar to a corresponding Month.
static Month toMonth(Date self)
Converts the Date to a corresponding Month.
static MonthDay toMonthDay(Calendar self)
Converts the Calendar to a corresponding MonthDay.
static MonthDay toMonthDay(Date self)
Converts the Date to a corresponding MonthDay.
static OffsetDateTime toOffsetDateTime(Calendar self)
Converts the Calendar to a corresponding OffsetDateTime.
static OffsetDateTime toOffsetDateTime(Date self)
Converts the Date to a corresponding OffsetDateTime.
static OffsetTime toOffsetTime(Calendar self)
Converts the Calendar to a corresponding OffsetTime.
static OffsetTime toOffsetTime(Date self)
Converts the Date to a corresponding OffsetTime.
static TimeZone toTimeZone(ZoneId self)
Returns a TimeZone equivalent to this zone.
static TimeZone toTimeZone(ZoneOffset self)
Returns a generally equivalent TimeZone.
static Year toYear(Calendar self)
Converts the Calendar to a corresponding Year.
static Year toYear(Date self)
Converts the Date to a corresponding Year.
static YearMonth toYearMonth(Calendar self)
Converts the Calendar to a corresponding YearMonth.
static YearMonth toYearMonth(Date self)
Converts the Date to a corresponding YearMonth.
static ZoneOffset toZoneOffset(TimeZone self)
Converts the TimeZone to a corresponding ZoneOffset.
static ZoneOffset toZoneOffset(TimeZone self, Instant instant)
Converts this TimeZone to a corresponding ZoneOffset.
static ZonedDateTime toZonedDateTime(Calendar self)
static ZonedDateTime toZonedDateTime(Date self)
Converts the Date to a corresponding ZonedDateTime.
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.
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.

Inherited Methods Summary

Inherited Methods
Methods inherited from class Name
class Object wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll

Method Detail

public static LocalDateTime clearTime(LocalDateTime self)

Returns a LocalDateTime with the time portion cleared.

Parameters:
self - a LocalDateTime
Returns:
a LocalDateTime
Since:
2.5.0

public static OffsetDateTime clearTime(OffsetDateTime self)

Returns an OffsetDateTime with the time portion cleared.

Parameters:
self - an OffsetDateTime
Returns:
an OffsetDateTime
Since:
2.5.0

public static ZonedDateTime clearTime(ZonedDateTime self)

Returns an ZonedDateTime with the time portion cleared.

Parameters:
self - a ZonedDateTime
Returns:
a ZonedDateTime
Since:
2.5.0

public static Duration div(Duration self, long scalar)

Supports the division operator; equivalent to calling the Duration.dividedBy method.

Parameters:
self - a Duration
scalar - the value to divide by
Returns:
a Duration
Since:
2.5.0

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. The closure may accept a single Temporal argument.

The particular unit decremented by depends on the specific sub-type of Temporal. Most sub-types use a unit of ChronoUnit.SECONDS except for

throws:
GroovyRuntimeException if this value is earlier than to
throws:
GroovyRuntimeException if to is a different type than this
Parameters:
from - the starting Temporal
to - the ending Temporal
closure - the zero or one-argument closure to call
Since:
2.5.0

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. 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.

throws:
GroovyRuntimeException if this value is earlier than to
throws:
GroovyRuntimeException if to is a different type than this
Parameters:
from - the starting Temporal
to - the ending Temporal
unit - the TemporalUnit to increment by
closure - the zero or one-argument closure to call
Since:
2.5.0

public static String format(LocalDate self, String pattern)

Formats this date with the provided DateTimeFormatter pattern.

Parameters:
self - a LocalDate
pattern - the formatting pattern
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static String format(LocalDate self, FormatStyle dateStyle)

Formats this date in the provided, localized FormatStyle.

Parameters:
self - a LocalDate
dateStyle - the FormatStyle
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static String format(LocalDateTime self, String pattern)

Formats this date/time with the provided DateTimeFormatter pattern.

Parameters:
self - a LocalDateTime
pattern - the formatting pattern
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static String format(LocalDateTime self, FormatStyle dateTimeStyle)

Formats this date/time in the provided, localized FormatStyle.

Parameters:
self - a LocalDateTime
dateTimeStyle - the FormatStyle
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static String format(LocalTime self, String pattern)

Formats this time with the provided DateTimeFormatter pattern.

Parameters:
self - a LocalDateTime
pattern - the formatting pattern
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static String format(LocalTime self, FormatStyle timeStyle)

Formats this time in the provided, localized FormatStyle.

Parameters:
self - a LocalTime
timeStyle - the FormatStyle
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static String format(OffsetDateTime self, String pattern)

Formats this date/time with the provided DateTimeFormatter pattern.

Parameters:
self - an OffsetDateTime
pattern - the formatting pattern
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static String format(OffsetDateTime self, FormatStyle dateTimeStyle)

Formats this date/time in the provided, localized FormatStyle.

Parameters:
self - an OffsetDateTime
dateTimeStyle - the FormatStyle
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static String format(OffsetTime self, String pattern)

Formats this time with the provided DateTimeFormatter pattern.

Parameters:
self - an OffsetTime
pattern - the formatting pattern
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static String format(OffsetTime self, FormatStyle timeStyle)

Formats this time in the provided, localized FormatStyle.

Parameters:
self - an OffsetTime
timeStyle - the FormatStyle
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static String format(ZonedDateTime self, String pattern)

Formats this date/time with the provided DateTimeFormatter pattern.

Parameters:
self - a ZonedDateTime
pattern - the formatting pattern
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static String format(ZonedDateTime self, FormatStyle dateTimeStyle)

Formats this date/time in the provided, localized FormatStyle.

Parameters:
self - a ZonedDateTime
dateTimeStyle - the FormatStyle
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static long getAt(TemporalAccessor self, TemporalField field)

Supports the getAt operator; equivalent to calling the TemporalAccessor.getLong method.

throws:
DateTimeException if a value for the field cannot be obtained
throws:
UnsupportedTemporalTypeException if the field is not supported
throws:
ArithmeticException if numeric overflow occurs
Parameters:
self - a TemporalAccessor
field - a non-null TemporalField
Returns:
the value for the field
Since:
2.5.0

public static long getAt(TemporalAmount self, TemporalUnit unit)

Supports the getAt operator; equivalent to calling the TemporalAmount.get method.

throws:
DateTimeException if a value for the field cannot be obtained
throws:
UnsupportedTemporalTypeException if the field is not supported
throws:
ArithmeticException if numeric overflow occurs
Parameters:
self - a TemporalAmount
unit - a non-null TemporalUnit
Returns:
the value for the field
Since:
2.5.0

public static long getAt(ZoneOffset self, TemporalField field)

Supports the getAt operator; equivalent to calling the ZoneOffset.getLong method.

Parameters:
self - a ZoneOffset
field - a TemporalField
Returns:
the ZoneOffset's field value
Since:
2.5.0

public static String getDateString(LocalDate self)

Formats this date with the DateTimeFormatter.ISO_LOCAL_DATE formatter.

Parameters:
self - a LocalDate
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static String getDateString(LocalDateTime self)

Formats this date/time with the DateTimeFormatter.ISO_LOCAL_DATE formatter.

Parameters:
self - a LocalDateTime
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static String getDateString(OffsetDateTime self)

Formats this date/time with the DateTimeFormatter.ISO_OFFSET_DATE formatter.

Parameters:
self - an OffsetDateTime
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

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. 2018-03-10EST.

Parameters:
self - a ZonedDateTime
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static String getDateTimeString(LocalDateTime self)

Formats this date/time with the DateTimeFormatter.ISO_LOCAL_DATE_TIME formatter.

Parameters:
self - a LocalDateTime
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static String getDateTimeString(OffsetDateTime self)

Formats this date/time with the DateTimeFormatter.ISO_OFFSET_DATE_TIME formatter.

Parameters:
self - an OffsetDateTime
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

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. 2018-03-10T14:34:55.144EST.

Parameters:
self - a ZonedDateTime
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static int getEra(Year self)

Equivalent 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).

Parameters:
self - a Year
Returns:
an int representing the era
Since:
2.5.0

public static String getFullName(ZoneId self)

Returns the name of this zone formatted according to the TextStyle.FULL text style.

Parameters:
self - a ZoneId
Returns:
the full display name of the ZoneId
Since:
2.5.0

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.

Parameters:
self - a ZoneId
locale - a Locale
Returns:
the full display name of the ZoneId
Since:
2.5.0

public static int getHours(ZoneOffset self)

Returns the hours component of this offset. If the offset's total seconds are negative, a negative value will be returned.

Parameters:
self - a ZoneOffset
Returns:
the hours component value
Since:
2.5.0

public static int getMinutes(ZoneOffset self)

Returns the minutes component of this offset. If the offset's total seconds are negative, a negative value will be returned.

Parameters:
self - a ZoneOffset
Returns:
the minutes component value
Since:
2.5.0

public static ZoneOffset getOffset(ZoneId self)

Returns a ZoneOffset for this zone as of now.

Parameters:
self - a ZoneId
Returns:
a ZoneOffset
Since:
2.5.0

public static ZoneOffset getOffset(ZoneId self, Instant instant)

Returns a ZoneOffset for this zone as of the provided Instant.

Parameters:
self - a ZoneId
instant - an Instant
Returns:
a ZoneOffset
Since:
2.5.0

public static int getSeconds(ZoneOffset self)

Returns 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.

Parameters:
self - a ZoneOffset
Returns:
the seconds component value
Since:
2.5.0

public static String getShortName(ZoneId self)

Returns the name of this zone formatted according to the TextStyle.SHORT text style.

Parameters:
self - a ZoneId
Returns:
the short display name of the ZoneId
Since:
2.5.0

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.

Parameters:
self - a ZoneId
locale - a Locale
Returns:
the short display name of the ZoneId
Since:
2.5.0

public static String getTimeString(LocalDateTime self)

Formats this date/time with the DateTimeFormatter.ISO_LOCAL_TIME formatter.

Parameters:
self - a LocalDateTime
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static String getTimeString(LocalTime self)

Formats this time with the DateTimeFormatter.ISO_LOCAL_TIME formatter.

Parameters:
self - a LocalTime
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static String getTimeString(OffsetDateTime self)

Formats this date/time with the DateTimeFormatter.ISO_OFFSET_TIME formatter.

Parameters:
self - an OffsetDateTime
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static String getTimeString(OffsetTime self)

Formats this time with the DateTimeFormatter.ISO_OFFSET_TIME formatter.

Parameters:
self - an OffsetTime
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

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. 14:34:55.144EST.

Parameters:
self - a ZonedDateTime
Returns:
a formatted String
See Also:
DateTimeFormatter
Since:
2.5.0

public static int getYearOfEra(Year self)

Equivalent 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.

Parameters:
self - a Year
Returns:
the year value of the era
Since:
2.5.0

public static ZoneId getZoneId(Calendar self)

Returns the Time Zone of the Calendar as a java.time.ZoneId.

Parameters:
self - a Calendar
Returns:
a ZoneId
Since:
2.5.0

public static ZoneId getZoneId(Date self)

Returns the Time Zone of the Date as a ZoneId. This will typically be the system's default ZoneId.

Parameters:
self - a Date
Returns:
a ZoneId
Since:
2.5.0

public static ZoneOffset getZoneOffset(Calendar self)

Returns the Time Zone offset of the Calendar as a ZoneOffset.

Parameters:
self - a Calendar
Returns:
a ZoneOffset
Since:
2.5.0

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.

Parameters:
self - a Date
Returns:
a ZoneOffset
Since:
2.5.0

public static boolean isNonnegative(Duration self)

Returns true if this duration is zero or positive.

Parameters:
self - a Duration
Returns:
true if nonnegative
Since:
2.5.0

public static boolean isNonnegative(ChronoPeriod self)

Returns true if this period is zero or positive.

Parameters:
self - a ChronoPeriod
Returns:
true if nonnegative
Since:
2.5.0

public static boolean isNonpositive(Duration self)

Returns true if this duration is zero or negative.

Parameters:
self - a Duration
Returns:
true if nonpositive
Since:
2.5.0

public static boolean isNonpositive(ChronoPeriod self)

Returns true if this period is zero or negative.

Parameters:
self - a ChronoPeriod
Returns:
true if nonpositive
Since:
2.5.0

public static boolean isPositive(Duration self)

Returns true if this duration is positive, excluding zero.

Parameters:
self - a Duration
Returns:
true if positive
Since:
2.5.0

public static boolean isPositive(ChronoPeriod self)

Returns true if this period is positive, excluding zero.

Parameters:
self - a ChronoPeriod
Returns:
true if positive
Since:
2.5.0

public static boolean isWeekday(DayOfWeek self)

Returns true if the DayOfWeek is a weekday.

Returns:
true if this DayOfWeek is Monday through Friday
Since:
2.5.0

public static boolean isWeekend(DayOfWeek self)

Returns true if this day of the week is a weekend day (Saturday or Sunday).

Parameters:
self - a DayOfWeek
Returns:
true if this DayOfWeek is Saturday or Sunday
Since:
2.5.0

public static LocalDateTime leftShift(LocalDate self, LocalTime time)

Returns a LocalDateTime from this date and the provided LocalTime.

Parameters:
self - a LocalDate
time - a LocalTime
Returns:
a LocalDateTime
Since:
2.5.0

public static OffsetDateTime leftShift(LocalDate self, OffsetTime time)

Returns a OffsetDateTime from this date and the provided OffsetTime.

Parameters:
self - a LocalDate
time - an OffsetTime
Returns:
an OffsetDateTime
Since:
2.5.0

public static OffsetDateTime leftShift(LocalDateTime self, ZoneOffset offset)

Returns an OffsetDateTime of this date/time and the provided ZoneOffset.

Parameters:
self - a LocalDateTime
offset - a ZoneOffset
Returns:
an OffsetDateTime
Since:
2.5.0

public static ZonedDateTime leftShift(LocalDateTime self, ZoneId zone)

Returns a OffsetDateTime of this date/time and the provided ZoneId.

Parameters:
self - a LocalDateTime
zone - a ZoneId
Returns:
a ZonedDateTime
Since:
2.5.0

public static LocalDateTime leftShift(LocalTime self, LocalDate date)

Returns a LocalDateTime of this time and the provided LocalDate.

Parameters:
self - a LocalTime
date - a LocalDate
Returns:
a LocalDateTime
Since:
2.5.0

public static OffsetTime leftShift(LocalTime self, ZoneOffset offset)

Returns an OffsetTime of this time and the provided ZoneOffset.

Parameters:
self - a LocalTime
offset - a ZoneOffset
Returns:
an OffsetTime
Since:
2.5.0

public static LocalDate leftShift(MonthDay self, int year)

Returns a LocalDate of this month/day and the provided year.

Parameters:
self - a MonthDay
year - a year
Returns:
a LocalDate
Since:
2.5.0

public static LocalDate leftShift(MonthDay self, Year year)

Returns a LocalDate of this month/day and the provided Year.

Parameters:
self - a MonthDay
year - a Year
Returns:
a LocalDate
Since:
2.5.0

public static OffsetDateTime leftShift(OffsetTime self, LocalDate date)

Returns an OffsetDateTime of this time and the provided LocalDate.

Parameters:
self - an OffsetTime
date - a LocalDate
Returns:
an OffsetDateTime
Since:
2.5.0

public static YearMonth leftShift(Year self, Month month)

Returns a YearMonth of this year and the provided Month.

Parameters:
self - a Year
month - a Month
Returns:
a YearMonth
Since:
2.5.0

public static LocalDate leftShift(Year self, MonthDay monthDay)

Returns a LocalDate of this year on the given MonthDay.

Parameters:
self - a Year
monthDay - a MonthDay
Returns:
a LocalDate
Since:
2.5.0

public static LocalDate leftShift(YearMonth self, int dayOfMonth)

Returns a LocalDate of this year/month and the given day of the month.

Parameters:
self - a YearMonth
dayOfMonth - a day of the month
Returns:
a LocalDate
Since:
2.5.0

public static ZonedDateTime leftShift(ZoneId self, LocalDateTime dateTime)

Returns a ZonedDateTime of this zone and the given LocalDateTime.

Parameters:
self - a ZoneId
Returns:
a ZonedDateTime
Since:
2.5.0

public static OffsetDateTime leftShift(ZoneOffset self, LocalDateTime dateTime)

Returns an OffsetDateTime of this offset and the provided LocalDateTime.

Parameters:
self - a ZoneOffset
dateTime - a LocalDateTime
Returns:
an OffsetDateTime
Since:
2.5.0

public static OffsetTime leftShift(ZoneOffset self, LocalTime time)

Returns an OffsetDateTime of this offset and the provided LocalTime.

Parameters:
self - a ZoneOffset
time - a LocalTime
Returns:
an OffsetTime
Since:
2.5.0

public static MonthDay leftShift(Month self, int dayOfMonth)

Creates a MonthDay at the provided day of the month.

Parameters:
self - a Month
dayOfMonth - a day of the month
Returns:
a MonthDay
Since:
2.5.0

public static YearMonth leftShift(Month self, Year year)

Creates a YearMonth at the provided Year.

Parameters:
self - a Month
year - a Year
Returns:
a YearMonth
Since:
2.5.0

public static Duration minus(Duration self, long seconds)

Returns a Duration that is seconds seconds shorter that this duration.

Parameters:
self - a Duration
seconds - the number of seconds to subtract
Returns:
a Duration
Since:
2.5.0

public static Instant minus(Instant self, long seconds)

Returns an Instant that is seconds seconds before this instant.

Parameters:
self - an Instant
seconds - the number of seconds to subtract
Returns:
an Instant
Since:
2.5.0

public static LocalDate minus(LocalDate self, long days)

Returns a LocalDate that is days days before this date.

Parameters:
self - a LocalDate
days - the number of days to subtract
Returns:
a LocalDate
Since:
2.5.0

public static long minus(LocalDate self, LocalDate other)

Calculates the number of days between two dates

Parameters:
self - a LocalDate
other - the other LocalDate
Returns:
the number of days
Since:
3.0.0

public static LocalDateTime minus(LocalDateTime self, long seconds)

Returns a LocalDateTime that is seconds seconds before this date/time.

Parameters:
self - a LocalDateTime
seconds - the number of seconds to subtract
Returns:
a LocalDateTime
Since:
2.5.0

public static LocalTime minus(LocalTime self, long seconds)

Returns a LocalTime that is seconds seconds before this time.

Parameters:
self - a LocalTime
seconds - the number of seconds to subtract
Returns:
a LocalTime
Since:
2.5.0

public static OffsetDateTime minus(OffsetDateTime self, long seconds)

Returns an OffsetDateTime that is seconds seconds before this date/time.

Parameters:
self - an OffsetDateTime
seconds - the number of seconds to subtract
Returns:
an OffsetDateTime
Since:
2.5.0

public static OffsetTime minus(OffsetTime self, long seconds)

Returns an OffsetTime that is seconds seconds before this time.

Parameters:
self - an OffsetTime
seconds - the number of seconds to subtract
Returns:
an OffsetTime
Since:
2.5.0

public static Period minus(Period self, long days)

Returns a Period that is days days shorter than this period. No normalization is performed.

Parameters:
self - a Period
days - the number of days to decrease this Period by
Returns:
a Period
Since:
2.5.0

public static Year minus(Year self, long years)

Returns a Year that is years years before this year.

Parameters:
self - a Year
years - the number of years to subtract
Returns:
a Year
Since:
2.5.0

public static YearMonth minus(YearMonth self, long months)

Returns a YearMonth that is months months before this year/month.

Parameters:
self - a YearMonth
months - the number of months to subtract
Returns:
a Year
Since:
2.5.0

public static ZonedDateTime minus(ZonedDateTime self, long seconds)

Returns a ZonedDateTime that is seconds seconds before this date/time.

Parameters:
self - a ZonedDateTime
seconds - the number of seconds to subtract
Returns:
a ZonedDateTime
Since:
2.5.0

public static DayOfWeek minus(DayOfWeek self, int days)

Returns the DayOfWeek that is days many days before this day of the week.

Parameters:
self - a DayOfWeek
days - the number of days to move back
Returns:
the DayOfWeek
Since:
2.5.0

public static Month minus(Month self, int months)

Returns the Month that is months months before this month.

Parameters:
self - a Month
months - the number of months to move back
Returns:
the Month
Since:
2.5.0

public static Duration multiply(Duration self, long scalar)

Supports the multiplication operator; equivalent to calling the Duration.multipliedBy method.

Parameters:
self - a Duration
scalar - the value to multiply by
Returns:
a Duration
Since:
2.5.0

public static Period multiply(Period self, int scalar)

Supports the multiply operator; equivalent to calling the Period.multipliedBy method.

Parameters:
self - a Period
scalar - a scalar to multiply each unit by
Returns:
a Period
Since:
2.5.0

public static Duration negative(Duration self)

Supports the unary minus operator; equivalent to calling the Duration.negated method.

Parameters:
self - a Duration
Returns:
a Duration
Since:
2.5.0

public static Period negative(Period self)

Supports the unary minus operator; equivalent to calling the Period.negated method.

Parameters:
self - a Period
Returns:
a negated Period
Since:
2.5.0

public static Duration next(Duration self)

Returns a Duration that is one second longer than this duration.

Parameters:
self - a Duration
Returns:
a Duration
Since:
2.5.0

public static Instant next(Instant self)

Returns an Instant that is one second after this instant.

Parameters:
self - an Instant
Returns:
an Instant one second ahead
Since:
2.5.0

public static LocalDate next(LocalDate self)

Returns a LocalDate one day after this date.

Parameters:
self - a LocalDate
Returns:
the next day
Since:
2.5.0

public static LocalDateTime next(LocalDateTime self)

Returns a LocalDateTime that is one second after this date/time.

Parameters:
self - a LocalDateTime
Returns:
a LocalDateTime
Since:
2.5.0

public static LocalTime next(LocalTime self)

Returns a LocalTime that is one second after this time.

Parameters:
self - a LocalTime
Returns:
a LocalTime
Since:
2.5.0

public static OffsetDateTime next(OffsetDateTime self)

Returns an OffsetDateTime one second after this date/time.

Parameters:
self - an OffsetDateTime
Returns:
an OffsetDateTime
Since:
2.5.0

public static OffsetTime next(OffsetTime self)

Returns an OffsetTime that is one second after this time.

Parameters:
self - an OffsetTime
Returns:
an OffsetTime
Since:
2.5.0

public static Period next(Period self)

Returns a Period that is one day longer than this period. No normalization is performed.

Parameters:
self - a Period
Returns:
a Period one day longer in length
Since:
2.5.0

public static Year next(Year self)

Returns a Year after this year.

Parameters:
self - a Year
Returns:
the next Year
Since:
2.5.0

public static YearMonth next(YearMonth self)

Returns a YearMonth that is the month after this year/month.

Parameters:
self - a YearMonth
Returns:
the next YearMonth
Since:
2.5.0

public static ZonedDateTime next(ZonedDateTime self)

Returns a ZonedDateTime that is one second after this date/time.

Parameters:
self - a ZonedDateTime
Returns:
a ZonedDateTime
Since:
2.5.0

public static Duration plus(Duration self, long seconds)

Returns a Duration that is seconds seconds longer than this duration.

Parameters:
self - a Duration
seconds - the number of seconds to add
Returns:
a Duration
Since:
2.5.0

public static Instant plus(Instant self, long seconds)

Returns an Instant that is seconds seconds after this instant.

Parameters:
self - an Instant
seconds - the number of seconds to add
Returns:
an Instant
Since:
2.5.0

public static LocalDate plus(LocalDate self, long days)

Returns a LocalDate that is days days after this date.

Parameters:
self - a LocalDate
days - the number of days to add
Returns:
a LocalDate
Since:
2.5.0

public static LocalDateTime plus(LocalDateTime self, long seconds)

Returns a LocalDateTime that is seconds seconds after this date/time.

Parameters:
self - a LocalDateTime
seconds - the number of seconds to add
Returns:
a LocalDateTime
Since:
2.5.0

public static LocalTime plus(LocalTime self, long seconds)

Returns a LocalTime that is seconds seconds after this time.

Parameters:
self - a LocalTime
seconds - the number of seconds to add
Returns:
a LocalTime
Since:
2.5.0

public static OffsetDateTime plus(OffsetDateTime self, long seconds)

Returns an OffsetDateTime that is seconds seconds after this date/time.

Parameters:
self - an OffsetDateTime
seconds - the number of seconds to add
Returns:
an OffsetDateTime
Since:
2.5.0

public static OffsetTime plus(OffsetTime self, long seconds)

Returns an OffsetTime that is seconds seconds after this time.

Parameters:
self - an OffsetTime
seconds - the number of seconds to add
Returns:
an OffsetTime
Since:
2.5.0

public static Period plus(Period self, long days)

Returns a Period that is days days longer than this period. No normalization is performed.

Parameters:
self - a Period
days - the number of days to increase this Period by
Returns:
a Period
Since:
2.5.0

public static Year plus(Year self, long years)

Returns a Year that is years years after this year.

Parameters:
self - a Year
years - the number of years to add
Returns:
a Year
Since:
2.5.0

public static YearMonth plus(YearMonth self, long months)

Returns a YearMonth that is months months after this year/month.

Parameters:
self - a YearMonth
months - the number of months to add
Returns:
a Year
Since:
2.5.0

public static ZonedDateTime plus(ZonedDateTime self, long seconds)

Returns a ZonedDateTime that is seconds seconds after this date/time.

Parameters:
self - an ZonedDateTime
seconds - the number of seconds to add
Returns:
a ZonedDateTime
Since:
2.5.0

public static DayOfWeek plus(DayOfWeek self, int days)

Returns the DayOfWeek that is days many days after this day of the week.

Parameters:
self - a DayOfWeek
days - the number of days to move forward
Returns:
the DayOfWeek
Since:
2.5.0

public static Month plus(Month self, int months)

Returns the Month that is months months after this month.

Parameters:
self - a Month
months - the number of months move forward
Returns:
the Month
Since:
2.5.0

public static Duration positive(Duration self)

Supports the unary plus operator; equivalent to calling the Duration.abs method.

Parameters:
self - a Duration
Returns:
a Duration
Since:
2.5.0

public static Period positive(Period self)

Supports 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.

Parameters:
self - a Period
Returns:
a positive Period
Since:
2.5.0

public static Duration previous(Duration self)

Returns a Duration that is one second shorter than this duration.

Parameters:
self - a Duration
Returns:
a Duration
Since:
2.5.0

public static Instant previous(Instant self)

Returns an Instant that one second before this instant.

Parameters:
self - an Instant
Returns:
an Instant one second behind
Since:
2.5.0

public static LocalDate previous(LocalDate self)

Returns a LocalDate one day before this date.

Parameters:
self - a LocalDate
Returns:
the previous day
Since:
2.5.0

public static LocalDateTime previous(LocalDateTime self)

Returns a LocalDateTime that is one second before this date/time.

Parameters:
self - a LocalDateTime
Returns:
a LocalDateTime
Since:
2.5.0

public static LocalTime previous(LocalTime self)

Returns a LocalTime that is one second before this time.

Parameters:
self - a LocalTime
Returns:
a LocalTime
Since:
2.5.0

public static OffsetDateTime previous(OffsetDateTime self)

Returns an OffsetDateTime one second before this date/time.

Parameters:
self - an OffsetDateTime
Returns:
an OffsetDateTime
Since:
2.5.0

public static OffsetTime previous(OffsetTime self)

Returns an OffsetTime that is one second before this time.

Parameters:
self - an OffsetTime
Returns:
an OffsetTime
Since:
2.5.0

public static Period previous(Period self)

Returns a Period that is one day shorter than this period. No normalization is performed.

Parameters:
self - a Period
Returns:
a Period one day shorter in length
Since:
2.5.0

public static Year previous(Year self)

Returns a Year before this year.

Parameters:
self - a Year
Returns:
the previous Year
Since:
2.5.0

public static YearMonth previous(YearMonth self)

Returns a YearMonth that is the month before this year/month.

Parameters:
self - a YearMonth
Returns:
the previous YearMonth
Since:
2.5.0

public static ZonedDateTime previous(ZonedDateTime self)

Returns a ZonedDateTime that is one second before this date/time.

Parameters:
self - a ZonedDateTime
Returns:
a ZonedDateTime
Since:
2.5.0

public static TemporalAmount rightShift(Temporal self, Temporal other)

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 .

Parameters:
self - a Temporal
other - another Temporal of the same type
Returns:
an TemporalAmount between the two Temporals
Since:
2.5.0

public static Period rightShift(LocalDate self, LocalDate other)

Returns a Period equivalent to the time between this date (inclusive) and the provided LocalDate (exclusive).

Parameters:
self - a LocalDate
other - another LocalDate
Returns:
a Period representing the time between the two LocalDates
Since:
2.5.0

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).

Parameters:
self - a Year
year - another Year
Returns:
a Period between the Years
Since:
2.5.0

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).

Parameters:
self - a YearMonth
other - another YearMonth
Returns:
a Period
Since:
2.5.0

public static Calendar toCalendar(Instant self)

Returns a generally equivalent Calendar in the GMT time zone, truncated to milliseconds.

Parameters:
self - an Instant
Returns:
a Calendar
Since:
2.5.0

public static Calendar toCalendar(LocalDate self)

Returns an equivalent instance of Calendar. The time portion of the returned calendar is cleared and the time zone is the current system default.

Parameters:
self - a LocalDate
Returns:
a java.util.Calendar
Since:
2.5.0

public static Calendar toCalendar(LocalDateTime self)

Returns 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.

Parameters:
self - a LocalDateTime
Returns:
a java.util.Calendar
Since:
2.5.0

public static Calendar toCalendar(LocalTime self)

Returns 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.

Parameters:
self - a LocalTime
Returns:
a java.util.Calendar
Since:
2.5.0

public static Calendar toCalendar(OffsetDateTime self)

Returns 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.

Parameters:
self - an OffsetDateTime
Returns:
a java.util.Calendar
Since:
2.5.0

public static Calendar toCalendar(OffsetTime self)

Returns 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.

Parameters:
self - an OffsetTime
Returns:
a java.util.Calendar
Since:
2.5.0

public static Calendar toCalendar(ZonedDateTime self)

Returns 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.

Parameters:
self - an ZonedDateTime
Returns:
a java.util.Calendar
Since:
2.5.0

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.

Parameters:
self - an Instant
Returns:
a Date
Since:
2.5.0

public static Date toDate(LocalDate self)

Returns an equivalent instance of Date. The time portion of the returned date is cleared.

Parameters:
self - a LocalDate
Returns:
a java.util.Date
Since:
2.5.0

public static Date toDate(LocalDateTime self)

Returns a generally equivalent instance of Date. The time value of the returned date is truncated to milliseconds.

Parameters:
self - a LocalDateTime
Returns:
a java.util.Date
Since:
2.5.0

public static Date toDate(LocalTime self)

Returns a generally equivalent instance of Date. The day-month-year value of the returned date is today and the time is truncated to milliseconds.

Parameters:
self - a LocalTime
Returns:
a java.util.Date
Since:
2.5.0

public static Date toDate(OffsetDateTime self)

Returns 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.

Parameters:
self - an OffsetDateTime
Returns:
a java.util.Date
Since:
2.5.0

public static Date toDate(OffsetTime self)

Returns 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.

Parameters:
self - an OffsetTime
Returns:
a java.util.Date
Since:
2.5.0

public static Date toDate(ZonedDateTime self)

Returns 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.

Parameters:
self - a ZonedDateTime
Returns:
a java.util.Date
Since:
2.5.0

public static DayOfWeek toDayOfWeek(Calendar self)

Converts 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.

Parameters:
self - a Calendar
Returns:
a DayOfWeek
Since:
2.5.0

public static DayOfWeek toDayOfWeek(Date self)

Converts the Date to a corresponding DayOfWeek.

Parameters:
self - a Date
Returns:
a DayOfWeek
Since:
2.5.0

public static Instant toInstant(Calendar self)

Convenience method for converting a Calendar to a corresponding Instant.

Parameters:
self - a Calendar
Returns:
an Instant
Since:
2.5.0

public static LocalDate toLocalDate(Date self)

Converts the Date to a corresponding LocalDate.

Parameters:
self - a Date
Returns:
a LocalDate
Since:
2.5.0

public static LocalDateTime toLocalDateTime(Calendar self)

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.

Parameters:
self - a Calendar
Returns:
a LocalDateTime
Since:
2.5.0

public static LocalDateTime toLocalDateTime(Date self)

Converts the Date to a corresponding LocalDateTime.

Parameters:
self - a Date
Returns:
a LocalDateTime
Since:
2.5.0

public static LocalTime toLocalTime(Calendar self)

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.

Parameters:
self - a Calendar
Returns:
a LocalTime
Since:
2.5.0

public static LocalTime toLocalTime(Date self)

Converts the Date to a corresponding LocalTime.

Parameters:
self - a Date
Returns:
a LocalTime
Since:
2.5.0

public static Month toMonth(Calendar self)

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.

Parameters:
self - a Calendar
Returns:
a Month
Since:
2.5.0

public static Month toMonth(Date self)

Converts the Date to a corresponding Month.

Parameters:
self - a Date
Returns:
a Month
Since:
2.5.0

public static MonthDay toMonthDay(Calendar self)

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.

Parameters:
self - a Calendar
Returns:
a MonthDay
Since:
2.5.0

public static MonthDay toMonthDay(Date self)

Converts the Date to a corresponding MonthDay.

Parameters:
self - a Date
Returns:
a MonthDay
Since:
2.5.0

public static OffsetDateTime toOffsetDateTime(Calendar self)

Converts the Calendar to a corresponding OffsetDateTime.

Parameters:
self - a Calendar
Returns:
an OffsetDateTime
Since:
2.5.0

public static OffsetDateTime toOffsetDateTime(Date self)

Converts the Date to a corresponding OffsetDateTime.

Parameters:
self - a Date
Returns:
an OffsetDateTime
Since:
2.5.0

public static OffsetTime toOffsetTime(Calendar self)

Converts the Calendar to a corresponding OffsetTime.

Parameters:
self - a Calendar
Returns:
an OffsetTime
Since:
2.5.0

public static OffsetTime toOffsetTime(Date self)

Converts the Date to a corresponding OffsetTime.

Parameters:
self - a Date
Returns:
an OffsetTime
Since:
2.5.0

public static TimeZone toTimeZone(ZoneId self)

Returns a TimeZone equivalent to this zone.

Parameters:
self - a ZoneId
Returns:
a TimeZone
Since:
2.5.0

public static TimeZone toTimeZone(ZoneOffset self)

Returns a generally equivalent TimeZone. The offset will be truncated to minutes.

Parameters:
self - a ZoneOffset
Returns:
a TimeZone
Since:
2.5.0

public static Year toYear(Calendar self)

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.

Parameters:
self - a Calendar
Returns:
a Year
Since:
2.5.0

public static Year toYear(Date self)

Converts the Date to a corresponding Year.

Parameters:
self - a Date
Returns:
a Year
Since:
2.5.0

public static YearMonth toYearMonth(Calendar self)

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.

Parameters:
self - a Calendar
Returns:
a YearMonth
Since:
2.5.0

public static YearMonth toYearMonth(Date self)

Converts the Date to a corresponding YearMonth.

Parameters:
self - a Date
Returns:
a YearMonth
Since:
2.5.0

public static ZoneOffset toZoneOffset(TimeZone self)

Converts the TimeZone to a corresponding ZoneOffset. The offset is determined using the current date/time.

Parameters:
self - a TimeZone
Returns:
a ZoneOffset
Since:
2.5.0

public static ZoneOffset toZoneOffset(TimeZone self, Instant instant)

Converts this TimeZone to a corresponding ZoneOffset. The offset is determined using the date/time of specified Instant.

Parameters:
self - a TimeZone
Returns:
a ZoneOffset
Since:
2.5.0

public static ZonedDateTime toZonedDateTime(Calendar self)

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.

Parameters:
self - a Calendar
Returns:
a ZonedDateTime
Since:
2.5.0

public static ZonedDateTime toZonedDateTime(Date self)

Converts the Date to a corresponding ZonedDateTime.

Parameters:
self - a Date
Returns:
a ZonedDateTime
Since:
2.5.0

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. The closure may accept a single Temporal argument.

The particular unit incremented by depends on the specific sub-type of Temporal. Most sub-types use a unit of ChronoUnit.SECONDS except for

throws:
GroovyRuntimeException if this value is later than to
throws:
GroovyRuntimeException if to is a different type than this
Parameters:
from - the starting Temporal
to - the ending Temporal
closure - the zero or one-argument closure to call
Since:
2.5.0

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. 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.

throws:
GroovyRuntimeException if this value is later than to
throws:
GroovyRuntimeException if to is a different type than this
Parameters:
from - the starting Temporal
to - the ending Temporal
unit - the TemporalUnit to increment by
closure - the zero or one-argument closure to call
Since:
2.5.0

© 2003-2020 The Apache Software Foundation
Licensed under the Apache license.
https://docs.groovy-lang.org/2.5.14/html/gapi/org/apache/groovy/datetime/extensions/DateTimeExtensions.html