简体   繁体   English

Python 中的“美国/东部”与“美国东部时间”时区

[英]"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.

相关问题 Python strptime 未解析时区 EST %z - Python strptime not parsing time zone EST %z 时区“东部标准时间”未被识别 - time zone “Eastern Standard Time” not recognized 对“美国/东部”区域使用“groupby”时输出错误 - Wrong output when using 'groupby' for 'US/Eastern' zone 如何在python中将UTC-4转换为US / Eastern? - How to convert UTC-4 to US/Eastern in python? pandas tz_convert:EST,US / Eastern和America / New_York之间的差异 - pandas tz_convert: difference among EST, US/Eastern and America/New_York 如何在 Python 中将美国/东部时区转换为美国/中部 - How do I convert US/Eastern timezone to US/Central in Python “美国/太平洋”时区的Python Django时区转换时间不正确 - Python Django Time Zone Conversion Incorrect Time for 'US/Pacific' Time Zone 将美国/东部转换为 UTC,包括夏令时 Python - Convert US/Eastern to UTC including daylight savings Python 如何让python显示当前时间(东部) - How to get python to display current time (eastern) 如何使用时区偏移量转换 Python Pandas 中的时间戳列列表 1) 转换为 UTC 2) 转换为 EST 3) 删除 TZ 偏移量并按原样存储 - How to convert list of timestamp columns in Python Pandas with Time zone offset 1) Convert to UTC 2) Convert to EST 3) Remove TZ offset & store as is
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM