转换为UTC时间戳

转换为UTC时间戳,第1张

转换为UTC时间
def getDateAndTime(seconds=None): """  Converts seconds since the Epoch to a time tuple expressing UTC.  When 'seconds' is not passed in, convert the current time instead.  :Parameters:      - `seconds`: time in seconds from the epoch.  :Return:      Time in UTC format."""return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(seconds))`

这会将当地时间转换为UTC

time.mktime(time.localtime(calendar.timegm(utc_time)))

http://feihonghsu.blogspot.com/2008/02/converting-from-local-time-to-
utc.html

如果使用mktime将struct_time转换为自大纪元以来的秒数,则此转换 位于本地时区中
。没有办法告诉它使用任何特定的时区,甚至不使用UTC。标准的“时间”包始终假定时间在您当地的时区中。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5667957.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存