是否有time.gmtime()的反函数将UTC元组解析为自纪元以来的秒数?

Tho*_*ele 21 python

python的时间模块似乎有点杂乱无章.例如,以下是docstring中的方法列表:

time() -- return current time in seconds since the Epoch as a float
clock() -- return CPU time since process start as a float
sleep() -- delay for a number of seconds given as a float
gmtime() -- convert seconds since Epoch to UTC tuple
localtime() -- convert seconds since Epoch to local time tuple
asctime() -- convert time tuple to string
ctime() -- convert time in seconds to string
mktime() -- convert local time tuple to seconds since Epoch
strftime() -- convert time tuple to string according to format specification
strptime() -- parse string to time tuple according to format specification
tzset() -- change the local timezone
Run Code Online (Sandbox Code Playgroud)

查看localtime()及其反mktime(),为什么gmtime()没有反转?

奖金问题:你怎么称呼这个方法?你会如何实现它?

Tom*_*Tom 34

实际上有一个反函数,但由于一些奇怪的原因,它在日历模块中:calendar.timegm().我列出了这个答案中的功能.

  • calendar.timegm(datetime.datetime.utcnow().utctimetuple())是获取UTC时间戳的一个班轮. (3认同)
  • Python:包括电池,但有时电池本身没有组装。 (2认同)