I'm Using Java 8,
Earlier in our code, We were using sdf.setTimeZone(TimeZone.getTimeZone("PDT"));
to convert to US Pacific which was failed(not throwing any errors but converted to default timezone) due to PDT is not a valid ZoneId.
So I look for setTimeZone(TimeZone.getTimeZone("PST"));
which is also not available in the TimeZone.getAvailableIDs()
values.
Finally I end up with using sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
Now, One of our friends using setTimeZone(TimeZone.getTimeZone("PST"));
to convert to us-pacific timezone and the conversion is happening properly..
Question is,
What is the difference between TimeZone.getTimeZone("PST");
and TimeZone.getTimeZone("America/Los_Angeles");
Which one is better to use ?
Quoting the documentation for Error Prone's ThreeLetterTimeZoneID check:
According to the Javadoc of
java.util.TimeZone
:For compatibility with JDK 1.1.x, some other three-letter time zone IDs (such as “PST”, “CTT”, “AST”) are also supported. However, their use is deprecated because the same abbreviation is often used for multiple time zones (for example, “CST” could be U.S. “Central Standard Time” and “China Standard Time”), and the Java platform can then only recognize one of them.
Aside from the ambiguity between timezones, there is inconsistency in the observance of Daylight Savings Time for the returned time zone, meaning the TimeZone obtained may not be what you expect. Examples include:
DateTime.getTimeZone("PST")
does observe daylight savings time; however, the identifier implies that it is Pacific Standard Time, i.e. daylight savings time is not observed.DateTime.getTimeZone("EST")
(and"MST"
and"HST"
) do not observe daylight savings time. However, this is inconsistent with PST (and others), so you may believe that daylight savings time will be observed.
So: Use the full America/Los_Angeles
format to minimize the ambiguity in the code.
According to the Java 8 Timezone documentation, PST
use is deprecated because the same abbreviation is often used for multiple time zones.
That's why is preferred to use America/Los_Angeles
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With