Java ZonedDateTime does not adjust UTC to local zone | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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
1 Resposta
+ 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