Package com.helger.commons.datetime
Class PDTWebDateHelper
java.lang.Object
com.helger.commons.datetime.PDTWebDateHelper
A helper class that parses Dates out of Strings with date time in RFC822 and
W3CDateTime formats plus the variants Atom (0.3) and RSS (0.9, 0.91, 0.92,
0.93, 0.94, 1.0 and 2.0) specificators added to those formats.
It uses the JDK java.text.SimpleDateFormat class attempting the parse using a mask for each one of the possible formats.
Original work Copyright 2004 Sun Microsystems, Inc.
It uses the JDK java.text.SimpleDateFormat class attempting the parse using a mask for each one of the possible formats.
Original work Copyright 2004 Sun Microsystems, Inc.
- Author:
- Alejandro Abdelnur (original; mainly the formatting masks), Philip Helger (major modification)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DateTimeFormatterstatic final DateTimeFormatterstatic final DateTimeFormatter -
Method Summary
Modifier and TypeMethodDescriptionstatic WithZoneIdextractDateTimeZone(String sDate) Extract the time zone from the passed string.static StringgetAsStringRFC822(LocalDateTime aDateTime) create a RFC822 representation of a date time using UTC date time zone.static StringgetAsStringRFC822(OffsetDateTime aDateTime) create a RFC822 representation of a date.static StringgetAsStringRFC822(ZonedDateTime aDateTime) create a RFC822 representation of a date.static StringgetAsStringW3C(LocalDateTime aDateTime) create a W3C Date Time representation of a date.static StringgetAsStringW3C(OffsetDateTime aDateTime) create a W3C Date Time representation of a date time using UTC date time zone.static StringgetAsStringW3C(ZonedDateTime aDateTime) create a W3C Date Time representation of a date time using UTC date time zone.static StringgetAsStringXSD(OffsetDate aOD) static Stringstatic Stringstatic Stringstatic StringgetAsStringXSD(LocalDate aLD) static StringgetAsStringXSD(LocalDateTime aLDT) static StringgetAsStringXSD(LocalTime aLT) static StringgetAsStringXSD(OffsetDateTime aODT) static StringgetAsStringXSD(OffsetTime aOT) static StringgetAsStringXSD(ZonedDateTime aZDT) static StringgetAsStringXSD(ZoneId aZoneID, ZonedDateTime aZDT) static Stringstatic Stringstatic ZonedDateTimegetDateTimeFromRFC822(String sDate) Parses a Date out of a String with a date in RFC822 format.static OffsetDateTimegetDateTimeFromW3C(String sDate) Parses a Date out of a String with a date in W3C date-time format.static ZonedDateTimegetDateTimeFromW3COrRFC822(String sDate) Parses a Date out of a String with a date in W3C date-time format or in a RFC822 format.static LocalDategetLocalDateFromXSD(String sValue) static LocalDateTimeParses a Date out of a String with a date in W3C date-time format or in a RFC822 format.static LocalDateTimegetLocalDateTimeFromXSD(String sValue) static LocalTimegetLocalTimeFromXSD(String sValue) static OffsetDategetOffsetDateFromXSD(String sValue) static OffsetDateTimegetOffsetDateTimeFromXSD(String sValue) static OffsetTimegetOffsetTimeFromXSD(String sValue) static XMLOffsetDategetXMLOffsetDateFromXSD(String sValue) static XMLOffsetDateTimegetXMLOffsetDateTimeFromXSD(String sValue) static XMLOffsetTimegetXMLOffsetTimeFromXSD(String sValue) static DateTimeFormatterstatic DateTimeFormattergetXSDFormatterDateTime(ZoneId aOverrideZoneID) static DateTimeFormatterstatic ZonedDateTimegetZonedDateTimeFromXSD(String sValue) static ZonedDateTimegetZonedDateTimeFromXSD(String sValue, ZoneId aZoneID) static OffsetDateTimeparseOffsetDateTimeUsingMask(PDTMask<?>[] aMasks, String sDate) Parses a Date out of a string using an array of masks.static ZonedDateTimeparseZonedDateTimeUsingMask(PDTMask<?>[] aMasks, String sDate, ZoneId aDTZ) Parses a Date out of a string using an array of masks.
-
Field Details
-
XSD_TIME
-
XSD_DATE
-
XSD_DATE_TIME
-
-
Method Details
-
parseOffsetDateTimeUsingMask
@Nullable public static OffsetDateTime parseOffsetDateTimeUsingMask(@Nonnull PDTMask<?>[] aMasks, @Nonnull @Nonempty String sDate) Parses a Date out of a string using an array of masks. It uses the masks in order until one of them succeeds or all fail.- Parameters:
aMasks- array of masks to use for parsing the stringsDate- string to parse for a date.- Returns:
- the Date represented by the given string using one of the given masks. It returns null if it was not possible to parse the the string with any of the masks.
-
parseZonedDateTimeUsingMask
@Nullable public static ZonedDateTime parseZonedDateTimeUsingMask(@Nonnull PDTMask<?>[] aMasks, @Nonnull @Nonempty String sDate, @Nullable ZoneId aDTZ) Parses a Date out of a string using an array of masks. It uses the masks in order until one of them succeeds or all fail.- Parameters:
aMasks- array of masks to use for parsing the stringsDate- string to parse for a date.aDTZ- The date/time zone to use. Optional.- Returns:
- the Date represented by the given string using one of the given masks. It returns null if it was not possible to parse the the string with any of the masks.
-
extractDateTimeZone
Extract the time zone from the passed string. UTC and GMT are supported.- Parameters:
sDate- The date string.- Returns:
- A non-
nullWithZoneId, where the remaining string to be parsed (nevernull) and and the extracted time zone (may benull) are contained.
-
getDateTimeFromRFC822
Parses a Date out of a String with a date in RFC822 format.
It parsers the following formats:- "EEE, dd MMM uuuu HH:mm:ss z"
- "EEE, dd MMM uuuu HH:mm z"
- "EEE, dd MMM uu HH:mm:ss z"
- "EEE, dd MMM uu HH:mm z"
- "dd MMM uuuu HH:mm:ss z"
- "dd MMM uuuu HH:mm z"
- "dd MMM uu HH:mm:ss z"
- "dd MMM uu HH:mm z"
Refer to the java.text.SimpleDateFormat javadocs for details on the format of each element.
- Parameters:
sDate- string to parse for a date. May benull.- Returns:
- the Date represented by the given RFC822 string. It returns
null if it was not possible to parse the given string into a
ZonedDateTimeor if the passedStringwasnull.
-
getDateTimeFromW3C
Parses a Date out of a String with a date in W3C date-time format.
It parsers the following formats:- "uuuu-MM-dd'T'HH:mm:ssz"
- "uuuu-MM-dd'T'HH:mmz"
- "uuuu-MM-dd"
- "uuuu-MM"
- "uuuu"
Refer to the java.text.SimpleDateFormat javadocs for details on the format of each element.
- Parameters:
sDate- string to parse for a date. May benull.- Returns:
- the Date represented by the given W3C date-time string. It returns
null if it was not possible to parse the given string into a
ZonedDateTimeor if the input string wasnull.
-
getDateTimeFromW3COrRFC822
Parses a Date out of a String with a date in W3C date-time format or in a RFC822 format.- Parameters:
sDate- string to parse for a date.- Returns:
- the Date represented by the given W3C date-time string. It returns null if it was not possible to parse the given string into a Date.
-
getLocalDateTimeFromW3COrRFC822
Parses a Date out of a String with a date in W3C date-time format or in a RFC822 format.- Parameters:
sDate- string to parse for a date.- Returns:
- the Date represented by the given W3C date-time string. It returns null if it was not possible to parse the given string into a Date.
-
getAsStringRFC822
create a RFC822 representation of a date.- Parameters:
aDateTime- Date to print. May benull.- Returns:
- the RFC822 represented by the given Date.
nullif the parameter isnull.
-
getAsStringRFC822
create a RFC822 representation of a date.- Parameters:
aDateTime- Date to print. May benull.- Returns:
- the RFC822 represented by the given Date.
nullif the parameter isnull.
-
getAsStringRFC822
create a RFC822 representation of a date time using UTC date time zone.- Parameters:
aDateTime- Date to print. May benull.- Returns:
- the RFC822 represented by the given Date.
nullif the parameter isnull.
-
getAsStringW3C
create a W3C Date Time representation of a date time using UTC date time zone.- Parameters:
aDateTime- Date to print. May not benull.- Returns:
- the W3C Date Time represented by the given Date.
-
getAsStringW3C
create a W3C Date Time representation of a date time using UTC date time zone.- Parameters:
aDateTime- Date to print. May not benull.- Returns:
- the W3C Date Time represented by the given Date.
-
getAsStringW3C
create a W3C Date Time representation of a date.- Parameters:
aDateTime- Date to print. May not benull.- Returns:
- the W3C Date Time represented by the given Date.
-
getCurrentDateTimeAsStringRFC822
- Returns:
- The current date time formatted using RFC 822
-
getCurrentDateTimeAsStringW3C
- Returns:
- The current date time formatted using W3C format
-
getXSDFormatterDateTime
-
getLocalDateTimeFromXSD
-
getAsStringXSD
-
getZonedDateTimeFromXSD
-
getZonedDateTimeFromXSD
-
getAsStringXSD
-
getAsStringXSD
-
getOffsetDateTimeFromXSD
-
getAsStringXSD
-
getXMLOffsetDateTimeFromXSD
-
getAsStringXSD
-
getXSDFormatterDate
-
getLocalDateFromXSD
-
getAsStringXSD
-
getOffsetDateFromXSD
-
getAsStringXSD
-
getXMLOffsetDateFromXSD
-
getAsStringXSD
-
getXSDFormatterTime
-
getLocalTimeFromXSD
-
getAsStringXSD
-
getOffsetTimeFromXSD
-
getAsStringXSD
-
getXMLOffsetTimeFromXSD
-
getAsStringXSD
-