How to Add & Subtract time code in Python

I have been developing some tools for the media production lately, i found a neat way to add or subtract certain amount of seconds to a given time code.

for example i have a video that starts from 12:45:05 and i want to add 59 seconds to it and use the new time.

from datetime import datetime
from datetime import timedelta
 
time = datetime(2009, 1, 1, 12, 45, 05, 0)
 
diff = timedelta(seconds = 59)
 
final_time = time + diff

Comments

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">