: 2017-18-08 12:60:30.345 ( 60 ), ( 12:60 11:45), (12:60), (11:45).
ZonedDateTime , String ( ).
:
, yyyy-dd-MM HH:mm:ss.SSS, 60 ( , ), ZonedDateTime, /.
, LocalDateTime, , / . UTC:
String timeDateStr = "2017-18-08 12:59:30.345";
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-dd-MM HH:mm:ss.SSS");
LocalDateTime dt = LocalDateTime.parse(timeDateStr, dtf);
Instant instant = dt.toInstant(ZoneOffset.UTC);
System.out.println(instant.toEpochMilli());
:
1503061170345
2017-18-08 12:59:30.345 UTC.
, ZoneId:
ZonedDateTime z = dt.atZone(ZoneId.of("Europe/London"));
System.out.println(z.toInstant().toEpochMilli());
:
1503057570345
, , / Instant ( / 2017-18-08 12:59:30.345 ).
, API IANA ( Region/City, America/Sao_Paulo Europe/Berlin).
(, CST PST), .
( , ), ZoneId.getAvailableZoneIds().
ZoneId.systemDefault(), , .
LocalDateTime offset (, -05:00 +03:00):
System.out.println(dt.toInstant(ZoneOffset.ofHours(3)).toEpochMilli());
/ +03:00 ( 3 UTC):
1503050370345
@MenoHochschild , , 60 ( java.time.format.ResolverStyle):
String timeDateStr = "2017-18-08 12:60:30.345";
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-dd-MM HH:mm:ss.SSS")
.withResolverStyle(ResolverStyle.LENIENT);
LocalDateTime dt = LocalDateTime.parse(timeDateStr, dtf);
60 , LocalDateTime :
2017-08-18T 13:00: 30,345
UTC ( ZoneOffset), .
( ZoneId), DST ( ) . , , (America/Sao_Paulo).
- DST 15 th 2017: 1 1 . , 00:00 00:59 . , :
ZoneId zone = ZoneId.of("America/Sao_Paulo");
// October 15th 2017 at midnight, DST starts in Sao Paulo
LocalDateTime d = LocalDateTime.of(2017, 10, 15, 0, 0, 0, 0);
ZonedDateTime z = d.atZone(zone);
System.out.println(z);// adjusted to 2017-10-15T01:00-02:00[America/Sao_Paulo]
DST: 18 th 2018 1 , 23 17 th. , 23:00 23:59 ( DST -DST), , :
LocalDateTime d = LocalDateTime.of(2018, 2, 17, 23, 0, 0, 0);
ZonedDateTime beforeDST = d.atZone(zone);
System.out.println(beforeDST);
ZonedDateTime afterDST = beforeDST.withLaterOffsetAtOverlap();
System.out.println(afterDST);
, DST (-02:00 -03:00). epochMilli.
, DST , .