如何使用小数秒使用calendar.timegm()

问题描述 投票:0回答:1

我有一个时间戳,自那个时代以来,我将其转换为秒。我一直在使用calendar.timegm(timestamp),但决定我也需要小数秒。我浏览了python文档,却找不到任何东西。有没有一种方法可以执行相同的转换,但不会忽略小数秒?

以下是我的时间戳示例:2011年1月4日00:00:20.498

所需的输出:978134435.something

python python-3.x timestamp unix-timestamp gps-time
1个回答
0
投票

您可以使用%f

from datetime import datetime
d = "Jan 04 2011 00:00:20.498"
x = datetime.timestamp(datetime.strptime(d, "%b %d %Y %H:%M:%S.%f").replace(microsecond=int(d.split('.')[1])))
print(x)
#1294099220.000498

[%f:微秒,十进制数,左侧零填充。

© www.soinside.com 2019 - 2024. All rights reserved.