java: timezone getTimeZone("GMT 0700")' timezone useDaylight incorrect

I want to get the time zone information for Los Angeles, now 10/10/2017 is daylight saving time, But I got a different result when I got the time zone in Los Angeles in two ways.

public class TimeZoneDemo2 {
  public static void main(String[] args) {
    TimeZone timeZoneLosAngeles = 

    TimeZone timeZoneGmtMinus07 = TimeZone.getTimeZone("GMT-07:00");

the result is:



My question is: Information about daylight saving time in time zone information obtained by "America/Los_Angeles". Why not include daylight saving time information (useDaylight = false) in the time zone information obtained by "GMT -0700"?

Jon Skeet

I want to get the time zone information for Los Angeles, now 10/10/2017 is daylight saving time

So you should ask for the "America/Los_Angeles" zone. That's what it's there for.

The "GMT-07:00" zone is a fixed-offset zone - it's only suitable when you want to represent "a time zone which is permanently seven hours behind UTC". That doesn't apply to Los Angeles.

There are plenty of other time zones which are sometimes at UTC-7 - why would you expect GMT-07:00 to mean "the time zone observed in Los Angeles"?

In other words, Java is doing the right thing - it's your expectations of what the "GMT-07:00" zone means that are incorrect.


See more on this question at Stackoverflow