Getting abbreviated name with daylight saving of a timezone in Java 8

Recently I wanted to get the timezone abbreviation of a timezone as a string. There are many tutorials which cover that. But in all those, timezone is given in one of the following formats. "America/Los-Angeles" or "PT".

But I needed to get the abbreviation with the daylight saving such as "PST" or "PDT". Finally, I was able to get it using the following method.

ZonedDateTime currentTime;
boolean isDayLightSavingEnabled =currentTime.getZone().getRules().isDaylightSavings(currentTime.toInstant());
TimeZone timeZone = TimeZone.getTimeZone(currentTime.getZone());
String timeZoneName = timeZone.getDisplayName(isDayLightSavingEnabled, TimeZone.SHORT);
System.out.println(timeZoneName);

Output will be
PST

Comments

Popular posts from this blog

Fixing Error "Failed to load VMMR0.r0 (VERR_SUPLIB_WORLD_WRITABLE)" in Virtualbox

Create new Java Class files at runtime

Using iReport plugin for Jasper Reports in Netbeans