Search code examples
pythonunix-timestamp

Why does python datetime.timestamp(0) return 1AM as opposed to 00:00


According to the definition of Unix time, it measures the number of seconds that have elapsed since 00:00 UTC on January 1st 1970. However, when I run datetime.fromtimestamp(0) using python 3.8, I get 1970-01-01 01:00:00. Why is it 1AM and not 00:00?


Solution

  • Timezones!!!

    Try this:

    from datetime import *
    print(datetime.fromtimestamp(0, timezone.utc))
    

    This gets the epoch time in UTC (+00:00)