Class ZonedDateTimeParser
Parses a string representation of a date to a ZonedDateTime.
Supported date string formats
-
A string parsable by
DateTimeFormatter, as per the format specified ingetFormat(). If the parser format represents a date without time, it will be set at the beginning of the day (midnight). If no format is explicitly set on the parser, parsing using other supported formats will be attempted before throwing aDateTimeException. - Digits only, representing milliseconds (EPOCH date).
-
TODAY[-+]9[YMDhms](see "Relative Dates" below) -
NOW[-+]9[YMDhms](see "Relative Dates" below)
Time zones
You can dictate which time zone the returned date-time should be,
with setZoneId(ZoneId).
If no zone id is set on the parser but the parser date format has a zone symbol, the returned date-time value will be set to the time zone detected in the date string value (if present). If no time zone is detected, the returned date-time zone will be UTC.
If a zone id is set on the parser and no time zone was parsed from the date strings, the returned date-time will be set to the parser zone id. Date strings with detected time zones will be converted to the parser zone id.
Relative dates
Date string values can be moment in time relative to the
current date using the TODAY or NOW keyword
(case sensitive), optionally followed by a number of time units to
add/remove.
TODAY is the current day without the hours, minutes, and
seconds (midnight), where as NOW is the current day with the
hours, minutes, and seconds. The time units that can be added or subtracted
are (case sensitive):
- Y: Year
- M: Month
- D: Day
- h: Hour
- m: Minute
- s: Second
For example, if today's date is July 1st 2023 and you want to represent
a year ago (without time), the format value would be:
TODAY-1Y.
-
Method Details
-
parse
Parses a string representation of a date.- Parameters:
dateString- representation of a date- Returns:
- a zoned date-time or null if the date string is blank.
- Throws:
DateTimeException- if the date string cannot be parsed
-
builder
-
getFormat
-
getLocale
-
getZoneId
-
setFormat
-
setLocale
-
setZoneId
-
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-