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 ?
SimpleDateFormat
norTimeZone
. Both classes are poorly designed and long outdated (the former in particular notoriously troublesome). Instead useDateTimeFormatter
andZoneId
, both from java.time, the modern Java date and time API, built into your Java 8 (and later). – Dripping