Search code examples
pythontimezonepytz

"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:


Solution

  • 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'.