开发者

Java time zone for Ottawa?

Why the TimeZone r开发者_如何学Pythoneturned by the following line showed incorrect time :

TimeZone.getTimeZone("America/Ottawa")

It showed 10:26 PM now [ Atlanta time now is 6:26 , Ottawashould also be 6:26 pm ].

I thought it has two parts : continent/city and it should return the correct time, am I incorrect ?


The correct timezone is America/Toronto. This is the largest city in the province of Ontario.

Timezone names are typically in the form Continent/City. For Canada and the United States, the timezones use the largest city in the State or Province. A few states have multiple timezones in the form of Continent/State/City. For most other countries there is at least one timezone using the largest city. Countries with multiple timezones usually use the largest city in each timezone.

EDIT: The likely reason for your time difference is that the code defaults to Zulu time if the timezone is not found.


You can't just pick cities at random. America/Toronto is the appropriate time zone if Java uses the same time zone database as everyone else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜