Though my belief was wrong, this answer is still providing some information, IMHO, which is potentially useful to people interested in this question. I was answering the question in one way (how to enumerate the supported timezones, though not with pytz), because I believed pytz did not provide a correct solution. In summary, you are not supposed to pass the result of pytz.timezone(…) to datetime, but should pass the datetime to its localize method.ĭespite his argument (and my bad for not reading the pytz documentation more carefully), I am going to keep this answer. Shanghai conforms to +0800, not +0806 as suggested by pytz: pytz.timezone('Asia/Shanghai')ĮDIT: Thanks to Mark Ransom's comment and downvote, now I know I am using pytz the wrong way. the timezone created by pytz is for the true local time, instead of the standard local time people observe. (Interestingly enough, the pytz installed by yum on CentOS 7 does not exhibit this problem.) import pytz The following piece of code shows the problem pytz can give. dateutil.tz can utilize the information there. If you are on a Unix-like platform, I would suggest you avoid pytz and look just at /usr/share/zoneinfo. I have honestly recorded my experience in an article "Time zones in Python". While it is arguable whether the pytz interface is error-prone, it can do things that dateutil.tz cannot do, especially regarding daylight-saving in the past or in the future. This answer is wrong, but I would rather retain it as a historical note. ,ĮDIT: I would appreciate it if you do not downvote this answer further. Here is a Python list of country codes, names, continents, capitals, and pytz timezones: countries = [
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |