pytz

Why do I get the offset 0:53 for timezone Europe/Berlin?

流过昼夜 提交于 2021-02-17 05:15:25
问题 Example Code from datetime import datetime, timezone import pytz tzstring = 'Europe/Berlin' t1 = datetime(2016, 6, 16, 2, 0, tzinfo=pytz.timezone(tzstring)) t2 = datetime(2016, 6, 16, 2, 0, tzinfo=timezone.utc).astimezone(pytz.timezone(tzstring)) Observed print(t1): 2016-06-16 02:00:00+00:53 print(t2): 2016-06-16 04:00:00+02:00 Expected print(t1): 2016-06-16 04:00:00+02:00 # does not match expectation print(t2): 2016-06-16 04:00:00+02:00 # matches expectation Question Can somebody please

python3数字、日期和时间

隐身守侯 提交于 2021-02-09 09:01:17
1、对数值进行取整 # 使用内建的round(value,ndigits)函数来取整,ndigits指定保留的位数,在取整时会取值在偶数上,如1.25取一位会取整1.2,1.26会取整1.3 In [1]: round(1.23,1 ) Out[ 1]: 1.2 In [ 2]: round(1.25,1 ) Out[ 2]: 1.2 In [ 3]: round(1.26,1 ) Out[ 3]: 1.3 In [ 4]: round(1.2645,3 ) Out[ 4]: 1.264 # 如果参数ndigits为负数的话会相应的取整到十位、白位和千位 In [1]: a = 1234567 In [ 2]: round(a,-1 ) Out[ 2]: 1234570 In [ 3]: round(a,-3 ) Out[ 3]: 1235000 # 通过格式化操作取小数精度 In [4]: x = 1.23456 In [ 5]: format(x, ' 0.2f ' ) Out[ 5]: ' 1.23 ' In [ 6]: ' value is {:0.3f} ' .format(x) Out[ 6]: ' value is 1.235 ' 2、执行精确的小数计算 # 在数学计算中由于CPU的浮点运算单元特性导致会引入微小的误差 In [11]: a = 4.2 In [ 12

Get country code for timezone using pytz?

大憨熊 提交于 2021-02-07 11:27:15
问题 I'm using pytz. I've read through the entire documentation sheet, but didn't see how this could be done. I have a timezone: America/Chicago. All I want is to get the respective country code for this timezone: US. It shows that I can do the opposite, such as: >>> country_timezones('ch') ['Europe/Zurich'] >>> country_timezones('CH') ['Europe/Zurich'] but I need to do it the other way around. Can this be done in Python, using pytz (or any other way for that matter)? 回答1: You can use the country

How to pick a timezone based on UTC offset?

你。 提交于 2021-02-05 06:21:33
问题 i've got a silly problem. I'm parsing Facebook user data, and I get the timezone as a number: timezone: The user's timezone offset from UTC For me ( 'America/Argentina/Buenos_Aires' ) it's -3. Now, how can I convert that number to a pytz.timezone ? Thank you! 回答1: There's not a 1:1 correspondence, so there's no way to do it without making some assumptions that are bound to be invalid. You can create your own tzinfo class that encodes the offset directly without trying to tie it back to a zone

How to pick a timezone based on UTC offset?

我的未来我决定 提交于 2021-02-05 06:21:26
问题 i've got a silly problem. I'm parsing Facebook user data, and I get the timezone as a number: timezone: The user's timezone offset from UTC For me ( 'America/Argentina/Buenos_Aires' ) it's -3. Now, how can I convert that number to a pytz.timezone ? Thank you! 回答1: There's not a 1:1 correspondence, so there's no way to do it without making some assumptions that are bound to be invalid. You can create your own tzinfo class that encodes the offset directly without trying to tie it back to a zone

Why is pytz offset incorrect?

主宰稳场 提交于 2021-01-28 10:43:13
问题 I have a python application that is sending email reminders to users in different timezones. The start time is set to a given date and time, and the reminder may be set to some number of minutes before the start time. The previous developer did not take into account the user's timezone, so reminders were always being sent based on the server's time. Using the pytz documentation, I initially tried using UTC for everything, and while this worked in development, the reminders were still off in

Why is pytz offset incorrect?

自古美人都是妖i 提交于 2021-01-28 10:42:40
问题 I have a python application that is sending email reminders to users in different timezones. The start time is set to a given date and time, and the reminder may be set to some number of minutes before the start time. The previous developer did not take into account the user's timezone, so reminders were always being sent based on the server's time. Using the pytz documentation, I initially tried using UTC for everything, and while this worked in development, the reminders were still off in

Pandas: Apply pytz.FixedOffset to a Series

﹥>﹥吖頭↗ 提交于 2021-01-28 09:39:33
问题 I have a DataFrame with a timestamp column which looks like this: 0 2020-01-26 05:00:00-08:00 1 2020-01-26 06:00:00-08:00 [...] Name: timestamp, dtype: datetime64[ns, pytz.FixedOffset(-480)] (The timestamp is not the DataFrame's index) I would like to have that pytz.FixedOffset(-480) applied (or rather un-applied) to the column, so that it would look like this: 0 2020-01-26 13:00:00 1 2020-01-26 14:00:00 [...] How can I achieve this without parsing timestamp manually? 回答1: Use Series.dt.tz

Pytz Localise on Aware Datetime

北城以北 提交于 2020-12-15 06:18:29
问题 I am trying to convert an aware datetime (UTC) to a local time using pytz. I was using this snippet of code, which lead to the time being off by a few minutes new_timezone = pytz.timezone(local_timezone) new_datetime = entry[1].replace(tzinfo=timezone.utc).astimezone(tz=new_timezone) I tried to do this, but get an error that it is not a naive datetime: local_timezone_pytz.localize(entry[1]) 回答1: use astimezone , e.g.: import datetime import pytz dt = datetime.datetime.now(datetime.timezone