简体   繁体   English

如何估计时间戳

[英]How to approximate timestamp

I have a list of time stamps with milliseconds like 10:35:08.23562515422 . 我有一个以毫秒为单位的时间戳列表,如10:35:08.23562515422 Now in the milliseconds, I want to have only first 3 values in the list like 10:35:08:235 . 现在,以毫秒为单位,我希望列表中只有前3个值,如10:35:08:235 Is there a way to do it? 有办法吗?

>>> from datetime import datetime

>>> timestamps = ['10:35:08.23562515422', '10:35:08.24862517422', '10:35:08.31060347422', '10:35:15.00860347422']

>>> for time in timestamps:
...     dt = datetime.strptime(time[:-8], '%H:%M:%S.%f')
...     print datetime.strftime(dt, '%H:%M:%S.%f')[:-3]

10:35:08.235
10:35:08.248
10:35:08.310
10:35:15.008

假设小时,分钟和秒始终都是两位数(它们应该是两位数),这很简单:

timestamp = timestamp[:12]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM