This post shows how to get your current timezone in Java using ZonedDateTime class.
Get Current Timezone Using ZonedDateTime
Since Java 8, it is possible to determine your current timezone using ZoneDateTime. Suppose you are in Singapore or thereabout; the following codes display your current time zone.
1 2 3 4 5 6 7 8 9 10 11 12 13 | package com.turreta.timezone; import java.time.ZoneId; import java.time.ZonedDateTime; public class WhatsMyTimeZone { public static void main(String[] args) { ZonedDateTime zdt = ZonedDateTime.now(); ZoneId zoneId = zdt.getZone(); System.out.println(zoneId); } } |
When we run the codes, we get the following output.
1 | Asia/Singpore |