For my work, I wanted to get an Instant date for a given date as per given ZoneID, Everything was wroking fine, but when I checked with old date (year 1883 or before). The time appears as 04:56, instead of 5:00.
For any date after 18 nov 1883, it gives me correct result like 1883-11-19T05:00:00Z
Can someone helps, why time appear as 4:56 for older dates ?
public static String firstdate = "18831118";
LocalDate localFirstDate = LocalDate.parse(firstdate, DateTimeFormatter.ofPattern("yyyyMMdd"));
LocalDateTime localDateTime = localFirstDate.atStartOfDay();
Instant instantFirstDate = localDateTime.toInstant(ZoneId.of("America/New_York").getRules().getOffset(localDateTime));
Output
1883-11-18T04:56:02Z
public static String firstdate = "18831119";
LocalDate localFirstDate = LocalDate.parse(firstdate, DateTimeFormatter.ofPattern("yyyyMMdd"));
LocalDateTime localDateTime = localFirstDate.atStartOfDay();
Instant instantFirstDate = localDateTime.toInstant(ZoneId.of("America/New_York").getRules().getOffset(localDateTime));
Output
1883-11-19T05:00:00Z
In the later case, it shows time perfectly 5:00:00Z