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

2
Leave a Reply

avatar
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
Me2reshPython Recent comment authors
  Subscribe  
Notify of
Python
Guest

Nice example!
If you have more such useful tips please post them at http://www.php2python.com too. I’m trying to build a resource for people moving from php to python.