简体   繁体   中英

How to convert seconds and miliseconds to epoch in python? Is it correct to add them to another epoch timestamp?

I have this string:

"00:00:45.0010796"

it's a time in seconds within a video. First of all, how can I convert this to an epoch string in python? Secondly, suppose that I have this string

"1512992049819"

It's the time that the video started (but it has year, month and date information in it aswell). After I convert the first string to epoch, if I add it to the second string (like I would add any two numbers), would the resulting epoch timestamp be correct?

This can easily be solved by using sub-strings.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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