[英]"US/Eastern" vs. "EST" time zone in Python
It is 2022/06/28 actually 28th of June 2022; 2022/06/28 实际上是 2022 年 6 月 28 日; I noticed when I try to get the current time from Python console two different results are possible the Eastern Time (Toronto, Montreal and New York).
我注意到当我尝试从 Python 控制台获取当前时间时,东部时间(多伦多、蒙特利尔和纽约)可能有两种不同的结果。 So what is the difference between these two parameters?
那么这两个参数有什么区别呢? I am going to answer the question:
我要回答这个问题:
"EST" is not accurate if you want to get the current time in New York because it represents Eastern Standard Time (UTC-05:00), which is one hour behind Eastern Daylight Time (UTC-04:00).如果您想获取纽约的当前时间,“EST”是不准确的,因为它代表东部标准时间 (UTC-05:00),比东部夏令时间 (UTC-04:00) 晚一小时。 Due to daylight savings, New York will observe either EST or EDT depending on the time of year.
由于夏令时,纽约将根据一年中的时间观察美国东部标准时间或美国东部时间。
"US/Eastern" is preferable to "EST" as it represents the Eastern Time Zone in the United States and will account for any shifts due to daylight savings. “US/Eastern”比“EST”更可取,因为它代表美国东部时区,并将考虑到夏令时引起的任何变化。 However, the zone representing "US/Eastern" has been renamed to "America/New_York", and is maintained for backwards compatibility.
但是,代表“US/Eastern”的区域已重命名为“America/New_York”,并保持向后兼容性。
The first way to get the current time in Toronto is:获取多伦多当前时间的第一种方法是:
from datetime import datetime
from pytz import timezone
tz = timezone('EST')
print(datetime.now(tz))
The output is the following:输出如下:
2022-06-28 16:23:23.333585-05:00
2022-06-28 16:23:23.333585-05:00
The second way to get the current time in Toronto is:获取多伦多当前时间的第二种方法是:
from datetime import datetime
from pytz import timezone
tz = timezone('US/Eastern')
print(datetime.now(tz))
The output is the following:输出如下:
2022-06-28 17:24:42.944669-04:00
2022-06-28 17:24:42.944669-04:00
Conclusion: If you use "EST" it is sometimes 1 hour ahead of the true time.结论:如果您使用“EST”,它有时会比实际时间提前 1 小时。 I recommend you usually use 'US/Eastern' .
我建议您通常使用'US/Eastern' 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.