Convert ZoneDateTime to String

Hi, sorry for the extremely basic question and bad english.
I need starting from a ZoneDateTime to print a date with the zone’s timezone applied, for example:

ZonedDateTime.now().format(DateTimeFormatter.ofPattern(“yyyy-MM-dd’T’HH:mm:ss”))

Print for me:
2023-03-12T14:00:27

But i live in Italy (GMT+1) and i want to print
2023-03-12T15:00:27

I googled the solution but evidently I’m wrong with the terms since I only find things that I don’t need or for Java.

Thanks in advance to anyone who can help me.

You find solutions for Java, because ZonedDateTime is a part of Java stdlib, not Kotlin. And solutions for Java should work correctly for Kotlin as well.

You simply need to specify the timezone:

ZonedDateTime.now(ZoneId.of("Europe/Rome"))

If we don’t specify the timezone explicitly, it uses OS system settings. If you get UTC time, then it seems your OS is set to use UTC or JVM somehow doesn’t pick up OS settings correctly.

1 Like

I knew I was missing out on some stupid…

Thanks a lot for the help, I fixed it.