Here you can find the source of toUTCZonedDateTime(String dateString)
e.g.
Parameter | Description |
---|---|
dateString | e.g. |
public static Optional<ZonedDateTime> toUTCZonedDateTime(String dateString)
//package com.java2s; //License from project: Open Source License import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.util.Optional; public class Main { private static final ZoneId UTC = ZoneId.of("Z"); private static DateTimeFormatter dateTimeFormatterAny = DateTimeFormatter.ISO_ZONED_DATE_TIME; /**// ww w . ja va 2s . c om * Converts any valid ZonedDateTime String (ISO_8601) representation to a UTC ZonedDateTime * <p> * e.g. <br/> * 1. 2010-01-01T12:00:00+01:00[Europe/Paris] ==> ZonedDateTime("2010-12-31T22:59:59.132Z") <br/> * 2. 2010-12-31T22:59:59.132Z ==> ZonedDateTime("2010-12-31T22:59:59.132Z") <br/> * </p> * * @param dateString e.g. * @return @ZonedDateTime instance represented by dateString in UTC ("Z") or * @Optional.empty() if the dateString does not represent a valid ISO_8601 zone string * @see "https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html" */ public static Optional<ZonedDateTime> toUTCZonedDateTime(String dateString) { try { ZonedDateTime utcDateTime = ZonedDateTime.parse(dateString, dateTimeFormatterAny) .withZoneSameInstant(UTC); return Optional.of(utcDateTime); } catch (DateTimeParseException ex) { return Optional.empty(); } } }