I’m trying to get the short name for the system default timezone using java.time.ZoneId. However, the API is returning an unexpected value. For example, when the server is in Asia/Kolkata, I am getting IT instead of IST. The same thing is happening when PT is returned instead of PST. Here is my code snippet:
The issue you are facing is due to the fact that ZoneId.systemDefault() returns the system default timezone, which can sometimes be in the format of a three-letter abbreviation that is not well-known or standardized.
To get the well-known short name for the timezone, you can use the java.util.TimeZone class instead. Here is an updated code snippet that should give you the expected results:
This will give you the short name for the system default timezone in a well-known and standardized format, such as IST for Asia/Kolkata or PST for America/Los_Angeles.