Python - calendar.timegm() vs. time.mktime()

前端 未结 2 489
梦毁少年i
梦毁少年i 2020-11-29 19:15

I seem to have a hard time getting my head around this.

What\'s the difference between calendar.timegm() and time.mktime()?

Say I h

相关标签:
2条回答
  • 2020-11-29 19:22

    time.mktime() assumes that the passed tuple is in local time, calendar.timegm() assumes it's in GMT/UTC. Depending on the interpretation the tuple represents a different time, so the functions return different values (seconds since the epoch are UTC based).

    The difference between the values should be equal to the time zone offset of your local time zone.

    0 讨论(0)
  • 2020-11-29 19:45

    calendar.timegm converts from UTC timestamp, time.mktime converts from local time not UTC.

    8 hours difference in their results corresponds exactly to timezone of your location.

    0 讨论(0)
提交回复
热议问题