在 $PYTHONHOME/lib/python2.7/calendar.py 中,timegm 定义为
EPOCH = 1970
_EPOCH_ORD = datetime.date(EPOCH, 1, 1).toordinal()
def timegm(tuple):
"""Unrelated but handy function to calculate Unix timestamp from GMT."""
year, month, day, hour, minute, second = tuple[:6]
days = datetime.date(year, month, 1).toordinal() - _EPOCH_ORD + day - 1
hours = days*24 + hour
minutes = hours*60 + minute
seconds = minutes*60 + second
return seconds
有什么理由不计算天数:
days = datetime.date(year, month, day).toordinal() - _EPOCH_ORD
谁能想到前一个表达式会中断的情况?