Z - Zero-Timezone or Zulu-timezone - While Date comparison
While doing Date comparison i.e. BEFORE or AFTER consider
$LOCAL.DATETIME.AFTER:
$LOCAL.DATETIME.BEFORE:
Consider Z as explained in the subject.
Please read the attached PDF to this description. PDF file : Discussion around Z in Date - the PR.pdf
Precisely the suggested solution is also available in the PDF(PR).
public static LocalDateTime parseDate(String value) {
try {
ZonedDateTime zonedDateTime = ZonedDateTime.parse(value, DateTimeFormatter.ISO_DATE_TIME);
return zonedDateTime.withZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime();
} catch ( DateTimeParseException e ) {
return LocalDateTime.parse(value, DateTimeFormatter.ISO_DATE_TIME);
}
}
If
String value = "2019-06-15T11:21:53.211"; Then the effective
LocalDateTimewill be :2019-06-15T11:21:53.211(catchcode is executed and returned. Note the time is returned as-it-is)
if
String value = "2019-06-15T11:21:53.211Z"; Then the effective
LocalDateTimewill be :2019-06-15T12:21:53.211(In this case -trycode is executed n returned. Note- The time has 1hr difference)
The difference in time could be different depending on which timezone this code is executed.
@BartRobeyns , if you want to expand more on this, please go ahead!
Note that his will also allow parsing of other timezones, e.g.: 2019-06-15T11:21:53.211+02:00
It would also be good to include the http-date format (https://tools.ietf.org/html/rfc7231#section-7.1.1.1), so we can validate standard headers like 'Last-Modified'. This can easily be done by adding an extra entry in the cascade that uses DateTimeFormatter.RFC_1123_DATE_TIME. A sample of such a date: Sat, 06 Jul 2019 17:07:15 GMT