pytz US/Eastern converting timestamps back and forth
从时间和日期网站:
1 2 3 4 5 6 7 8 | Generalized Time Zone in New York ET Eastern Time UTC -5:00 / -4:00 Wed, 11:42:33 Time Zone Currently Being Used in New York UTC -5 EST Eastern Standard Time New York Wed, 11:42:33 Time Zone Not Currently Being Observed in New York UTC -4 EDT Eastern Daylight Time 10 Mar 2019 |
所以基本上纽约的时间是美国东部时间或美国东部时间,这取决于我们当前在哪个时段由于DayLight节省时间。
在pytz中使用US / Eastern时,它是指ET,EST还是EDT? 是否考虑了EST / EDT时间的变化?
我正在使用此代码获取东部时间给定日期的开始和结束时间戳:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | import datetime import pytz session = datetime.datetime.strptime('26/02/2019', '%d/%m/%Y') exchange_tz = pytz.timezone('US/Eastern') session_localized = exchange_tz.localize(session) _period1 = int((session_localized - datetime.datetime(1970, 1, 1, tzinfo=exchange_tz)).total_seconds()) _period2 = int((session_localized - datetime.datetime(1970, 1, 1, tzinfo=exchange_tz)).total_seconds()) + 24*60*60 >>> _period1 1551139200 >>> _period2 1551225600 |
我并非100%确定这些时间戳已正确生成。 因为当我尝试将它们转换回本地化的日期时间时,我得到1小时的差异:
1 2 3 4 5 | _exchange_tz = pytz.timezone('US/Eastern') _exchange_ts = _exchange_tz.localize( datetime.datetime.fromtimestamp(1551139200) ) >>> str(_exchange_ts) '2019-02-26 01:00:00-05:00' |
据我所知,它应该是
我还在pytz文档中读到,在进行算术覆盖时应该使用
When using
US/Eastern in pytz, does it refer to ET, EST or EDT?. Does it take into consideration the EST/EDT time change?
这些是IANA(又名TZDB,Olson等)时区标识符。
关于您的示例,时间戳