Python Glossary Русский

all Python 3calendarfunction

calendar.timegm()

dates and leap years

Converts a UTC time tuple (such as one from time.gmtime()) into seconds since the Unix epoch — the inverse of gmtime().

Syntax

calendar.timegm(tuple)

gmtime() pairs with timegm(), not time.mktime(): mktime() treats the tuple as local time and shifts the result by the machine's time zone. Only the first six fields are used; the weekday and the DST flag are ignored. Oddly, the function lives in calendar rather than in time.

Examples

import calendar, time
print(calendar.timegm((1970, 1, 2, 0, 0, 0)))  # → 86400
print(calendar.timegm(time.gmtime(1700000000)))  # → 1700000000
print(time.mktime((1970, 1, 2, 0, 0, 0, 0, 0, 0)))  # → ? зависит от часового пояса

See also

Open in the full glossarydocs.python.orgReport an inaccuracy