+ 1

Java ZonedDateTime does not adjust UTC to local zone

How can I print the adjusted time? I expect the result to be 2021-08-11T04:15.

11th Aug 2021, 12:33 AM
ScriptMaestro 🇳🇬
ScriptMaestro 🇳🇬 - avatar
2 odpowiedzi
+ 1
change zone of ZonedDateTime: //import java.time.ZoneId; //import java.time.ZonedDateTime; ZonedDateTime timeUTC = ZonedDateTime.now( ZoneId.of("UTC")); ZoneId localZone = ZoneId.of("Africa/Lagos"); //UTC +1h ZonedDateTime timeZoned = timeUTC.withZoneSameInstant( localZone); System.out.println( timeUTC); System.out.println( timeZoned);
17th Aug 2021, 7:52 AM
zemiak