Farzad Amirjavid
Farzad Amirjavid

Reputation: 725

"US/Eastern" vs. "EST" time zone in Python

It is 2022/06/28 actually 28th of June 2022; 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). So what is the difference between these two parameters? I am going to answer the question:

Upvotes: 3

Views: 4556

Answers (2)

gloo
gloo

Reputation: 721

"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). 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. However, the zone representing "US/Eastern" has been renamed to "America/New_York", and is maintained for backwards compatibility.

Upvotes: 6

Farzad Amirjavid
Farzad Amirjavid

Reputation: 725

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

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

Conclusion: If you use "EST" it is sometimes 1 hour ahead of the true time. I recommend you usually use 'US/Eastern'.

Upvotes: 2

Related Questions