【问题标题】:How to convert seconds and miliseconds to epoch in python? Is it correct to add them to another epoch timestamp?如何在python中将秒和毫秒转换为纪元?将它们添加到另一个纪元时间戳是否正确?
【发布时间】:2018-08-06 03:49:47
【问题描述】:

我有这个字符串:

"00:00:45.0010796"

这是一个视频中的时间,以秒为单位。首先,如何在 python 中将其转换为纪元字符串?其次,假设我有这个字符串

"1512992049819"

这是视频开始的时间(但其中也包含年、月和日期信息)。将第一个字符串转换为纪元后,如果将其添加到第二个字符串(就像添加任意两个数字一样),生成的纪元时间戳是否正确?

【问题讨论】:

    标签: python epoch


    【解决方案1】:

    这可以通过使用子字符串轻松解决。

    s1 = "00:00:45.0010796"
    s2 = "1512992049819"
    
    video_length = (int(s1[:2])*60*60 + int(s1[3:5])*60 + float(s1[6:]))*1000
    
    print(int(s2)+video_length)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-08
      • 2023-03-27
      • 2015-07-07
      • 2013-11-11
      • 2013-08-19
      • 2020-05-05
      • 2021-12-11
      • 1970-01-01
      相关资源
      最近更新 更多