It returns the default timezone for GMT.
Using the SimpleTimeFormat with \"z\" for timezone, it prints \"PDT\". But \"PDT\" is not in the list returned from TimeZo
"PDT" is an abbreviation for Pacific Daylight Time. It is used in conjunction with Pacific Standard Time to make up the Pacific time zone.
The time zone identifier for the Pacific time zone is "America/Los_Angeles"
. You should use that instead.
Read the timezone tag wiki, and Wikipedia's article on the tz database.
PDT
is not a time zoneAnyone knows why "PDT" is not a standard tz?
Because “PDT” is not a time zone!
The “PDT” is a pseudo-time zone used by the media to indicate vaguely a set of time zones plus an indicator if they intended during the period when Daylight Saving Time (DST) is engaged or not (PST
). Avoid these 2-4 letter codes as they are not true time zones, not standardized, and are not even unique(!).
Specify a proper time zone name in the format of continent/region
, such as America/Montreal, Africa/Casablanca, or Pacific/Auckland
.
By PDT
any of these time zones, and more, may be intended:
ZoneId z = ZoneId.of( "America/Los_Angeles" ) ;
ZoneId z = ZoneId.of( "America/Tijuana" ) ;
ZoneId z = ZoneId.of( "America/Whitehorse" ) ;
But PDT
might not mean this zone as Arizona does not participate in the Daylight Saving Time (DST) nonsense, and the D
in the middle means DST.
ZoneId z = ZoneId.of( "America/Phoenix" ) ;
Avoid SimpleTimeFormat
class as it is a part of the troublesome old date-time classes that are now legacy, supplanted by the java.time classes. Use DateTimeFormatter instead.
Avoid TimeZone
as well. Replaced by ZoneId.
ZoneId
, not stringSomeone invokes my API passing in "PDT" as the timezone.
Change your API to take a ZoneId
as an argument, rather than a mere String. That ensures valid values and gives you type-safety.
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date, Calendar, & SimpleDateFormat.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.