Looking for ideas to convert time in long (millis) from UTC to EST Tried in the below manner and did not work. I am seeing epcohET is same as input parameter.
long time = 1693932120000
Instant dateTime = Instant.ofEpochMilli(time);
ZoneId usET = ServerTimeZone.TimeZone.getTimeZone("America/New_York").toZoneId();
ZonedDateTime zdt = ZonedDateTime.ofInstant(dateTime, usET);
long epochET = zdt.toInstant().toEpochMilli();
Instantrepresents just a moment in time and is independent of the timezone.You can use
Instant#atZoneto get the desired result.Demo:
Output:
Online Demo
Learn about the modern date-time API from Trail: Date Time