I am using the new Java LocalDateTime class as well as the Instant class. I have a database where the timestamp is stored as a long.
The question is why I have to use a ZoneDateTime When I can specifiy the ZoneID via a ofInstant from LocalDatetime
LocalDateTime.ofInstant(Instant.ofEpochMilli(1563387286000l),ZoneId.of("America/Panama"));
I am using this formatter
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss VV O");
This line produces throws an exception (Unable to extract value: class java.time.LocalDateTime)
localDateTime.format(dateTimeFormatter);
To fix the issue I had to use this code. It works fine.
LocalDateTime localDateTime =LocalDateTime.ofInstant(Instant.ofEpochMilli(1563387286000l),ZoneId.of("America/Panama"));
ZonedDateTime zone = ZonedDateTime.of(localDateTime,ZoneId.of("America/Panama"));
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss VV O");
localDateTime.format(dateTimeFormatter);
Based On what I have learned from Java DOC (Oracle)
LocalDateTime class represents a value without the ZoneID.
ofInstant method allows to obtain a LocalDateTime with the ZoneID(Offset) comprised.
My question: why can't we use LocalDatetime with the follwing formatter : DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss VV O");
This is fishy, maybe they have updated in the recent JDKs