Class DateTimeStaticExtensions
java.lang.Object
org.apache.groovy.datetime.extensions.DateTimeStaticExtensions
This class defines new static extension methods which appear on normal JDK
Date/Time API (java.time) classes inside the Groovy environment.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Period
Obtains a Period consisting of the number of years and months between twoYearMonth
instances.static Period
Obtains a Period consisting of the number of years between twoYear
instances.static LocalDate
parse
(LocalDate type, CharSequence text, String pattern) Parse text into aLocalDate
using the provided pattern.static LocalDateTime
parse
(LocalDateTime type, CharSequence text, String pattern) Parse text into aLocalDateTime
using the provided pattern.static LocalTime
parse
(LocalTime type, CharSequence text, String pattern) Parse text into aLocalTime
using the provided pattern.static MonthDay
parse
(MonthDay type, CharSequence text, String pattern) Parse text into aMonthDay
using the provided pattern.static OffsetDateTime
parse
(OffsetDateTime type, CharSequence text, String pattern) Parse text into anOffsetDateTime
using the provided pattern.static OffsetTime
parse
(OffsetTime type, CharSequence text, String pattern) Parse text into anOffsetTime
using the provided pattern.static YearMonth
parse
(YearMonth type, CharSequence text, String pattern) Parse text into aYearMonth
using the provided pattern.static Year
parse
(Year type, CharSequence text, String pattern) Parse text into aYear
using the provided pattern.static ZonedDateTime
parse
(ZonedDateTime type, CharSequence text, String pattern) Parse text into aZonedDateTime
using the provided pattern.static ZoneOffset
systemDefault
(ZoneOffset type) Returns theZoneOffset
currently associated with the system defaultZoneId
.
-
Method Details
-
parse
Parse text into aLocalDate
using the provided pattern. Note: the order of parameters differs from versions of this method for the legacy Date class.- Parameters:
type
- placeholder variable used by Groovy categories; ignored for default static methodstext
- String to be parsed to create the date instancepattern
- pattern used to parse the text- Returns:
- a LocalDate representing the parsed text
- Throws:
IllegalArgumentException
- if the pattern is invalidDateTimeParseException
- if the text cannot be parsed- Since:
- 2.5.0
- See Also:
-
parse
Parse text into aLocalDateTime
using the provided pattern. Note: the order of parameters differs from versions of this method for the legacy Date class.- Parameters:
type
- placeholder variable used by Groovy categories; ignored for default static methodstext
- String to be parsed to create the date instancepattern
- pattern used to parse the text- Returns:
- a LocalDateTime representing the parsed text
- Throws:
IllegalArgumentException
- if the pattern is invalidDateTimeParseException
- if the text cannot be parsed- Since:
- 2.5.0
- See Also:
-
parse
Parse text into aLocalTime
using the provided pattern.- Parameters:
type
- placeholder variable used by Groovy categories; ignored for default static methodstext
- String to be parsed to create the date instancepattern
- pattern used to parse the text- Returns:
- a LocalTime representing the parsed text
- Throws:
IllegalArgumentException
- if the pattern is invalidDateTimeParseException
- if the text cannot be parsed- Since:
- 2.5.0
- See Also:
-
parse
Parse text into aMonthDay
using the provided pattern.- Parameters:
type
- placeholder variable used by Groovy categories; ignored for default static methodstext
- String to be parsed to create the date instancepattern
- pattern used to parse the text- Returns:
- a MonthDay representing the parsed text
- Throws:
IllegalArgumentException
- if the pattern is invalidDateTimeParseException
- if the text cannot be parsed- Since:
- 2.5.0
- See Also:
-
parse
Parse text into anOffsetDateTime
using the provided pattern.- Parameters:
type
- placeholder variable used by Groovy categories; ignored for default static methodstext
- String to be parsed to create the date instancepattern
- pattern used to parse the text- Returns:
- an OffsetDateTime representing the parsed text
- Throws:
IllegalArgumentException
- if the pattern is invalidDateTimeParseException
- if the text cannot be parsed- Since:
- 2.5.0
- See Also:
-
parse
Parse text into anOffsetTime
using the provided pattern.- Parameters:
type
- placeholder variable used by Groovy categories; ignored for default static methodstext
- String to be parsed to create the date instancepattern
- pattern used to parse the text- Returns:
- an OffsetTime representing the parsed text
- Throws:
IllegalArgumentException
- if the pattern is invalidDateTimeParseException
- if the text cannot be parsed- Since:
- 2.5.0
- See Also:
-
parse
Parse text into aYear
using the provided pattern.- Parameters:
type
- placeholder variable used by Groovy categories; ignored for default static methodstext
- String to be parsed to create the date instancepattern
- pattern used to parse the text- Returns:
- a Year representing the parsed text
- Throws:
IllegalArgumentException
- if the pattern is invalidDateTimeParseException
- if the text cannot be parsed- Since:
- 2.5.0
- See Also:
-
parse
Parse text into aYearMonth
using the provided pattern.- Parameters:
type
- placeholder variable used by Groovy categories; ignored for default static methodstext
- String to be parsed to create the date instancepattern
- pattern used to parse the text- Returns:
- a YearMonth representing the parsed text
- Throws:
IllegalArgumentException
- if the pattern is invalidDateTimeParseException
- if the text cannot be parsed- Since:
- 2.5.0
- See Also:
-
parse
Parse text into aZonedDateTime
using the provided pattern.- Parameters:
type
- placeholder variable used by Groovy categories; ignored for default static methodstext
- String to be parsed to create the date instancepattern
- pattern used to parse the text- Returns:
- a ZonedDateTime representing the parsed text
- Throws:
IllegalArgumentException
- if the pattern is invalidDateTimeParseException
- if the text cannot be parsed- Since:
- 2.5.0
- See Also:
-
systemDefault
Returns theZoneOffset
currently associated with the system defaultZoneId
.- Parameters:
type
- placeholder variable used by Groovy categories; ignored for default static methods- Returns:
- a ZoneOffset
- Since:
- 2.5.0
- See Also:
-
between
Obtains a Period consisting of the number of years between twoYear
instances. The months and days of the Period will be zero. The result of this method can be a negative period if the end is before the start. -
between
Obtains a Period consisting of the number of years and months between twoYearMonth
instances. The days of the Period will be zero. The result of this method can be a negative period if the end is before the start.
-