pytz

How to get system timezone setting and pass it to pytz.timezone?

余生颓废 提交于 2019-11-26 02:23:20
问题 We can use time.tzname get a local timezone name, but that name is not compatible with pytz.timezone . In fact, the name returned by time.tzname is ambiguous. This method returns (\'CST\', \'CST\') in my system, but \'CST\' can indicate four timezones: Central Time Zone (North America) - observed in North America\'s Central Time Zone China Standard Time Chungyuan Standard Time - the term \"Chungyuan Standard Time\" is now rarely in use in Taiwan Australian Central Standard Time (ACST) 回答1:

How do I get the UTC time of “midnight” for a given timezone?

删除回忆录丶 提交于 2019-11-26 00:59:54
问题 The best I can come up with for now is this monstrosity: >>> datetime.utcnow() \\ ... .replace(tzinfo=pytz.UTC) \\ ... .astimezone(pytz.timezone(\"Australia/Melbourne\")) \\ ... .replace(hour=0,minute=0,second=0,microsecond=0) \\ ... .astimezone(pytz.UTC) \\ ... .replace(tzinfo=None) datetime.datetime(2008, 12, 16, 13, 0) I.e., in English, get the current time (in UTC), convert it to some other timezone, set the time to midnight, then convert back to UTC. I\'m not just using now() or

Is there a list of Pytz Timezones?

和自甴很熟 提交于 2019-11-26 00:26:37
问题 I would like to know what are all the possible values for the timezone argument in the Python library pytz. How to do it? SOLUTION for tz in pytz.all_timezones: print tz Africa/Abidjan Africa/Accra Africa/Addis_Ababa Africa/Algiers Africa/Asmara Africa/Asmera Africa/Bamako Africa/Bangui Africa/Banjul Africa/Bissau Africa/Blantyre Africa/Brazzaville Africa/Bujumbura Africa/Cairo Africa/Casablanca Africa/Ceuta Africa/Conakry Africa/Dakar Africa/Dar_es_Salaam Africa/Djibouti Africa/Douala Africa

How do I get the UTC time of “midnight” for a given timezone?

南楼画角 提交于 2019-11-25 22:16:22
The best I can come up with for now is this monstrosity: >>> datetime.utcnow() \ ... .replace(tzinfo=pytz.UTC) \ ... .astimezone(pytz.timezone("Australia/Melbourne")) \ ... .replace(hour=0,minute=0,second=0,microsecond=0) \ ... .astimezone(pytz.UTC) \ ... .replace(tzinfo=None) datetime.datetime(2008, 12, 16, 13, 0) I.e., in English, get the current time (in UTC), convert it to some other timezone, set the time to midnight, then convert back to UTC. I'm not just using now() or localtime() as that would use the server's timezone, not the user's timezone. I can't help feeling I'm missing