gpt4 book ai didi

Python:自 1970.01.01 GMT 午夜到任意时间 GMT 的秒数?

转载 作者:行者123 更新时间:2023-11-30 23:42:21 26 4
gpt4 key购买 nike

在这方面遇到了困难,尝试了所有这些不同的日期函数,但不知道如何确定地做到这一点。

最佳答案

您可以使用calendar.timegm来获取自纪元以来的秒数。时间元组是必需的参数,time.strptime 可用于生成该元组。

这是一个简单的示例:

import calendar
import time

# Time in GMT
x = 'Sat Jul 14 22:05:54 2012'
y = time.strptime(x)
z = calendar.timegm(y)
print z # 1342303554 - the number of seconds since epoch

关于Python:自 1970.01.01 GMT 午夜到任意时间 GMT 的秒数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11489706/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com