how to calculate timedelta python
<p>What I am trying to do is to subtract 7 hours from a date. I searched stack overflow and found the answer on how to do it <a href="http://stackoverflow.com/questions/3298935/adding-2-1-2-hours-to-a-time-object-in-python">here</a>. I then went to go read the documentation on <a href="http://docs.python.org/library/datetime.html#datetime.timedelta" rel="nofollow">timedelta</a> because I was unable to understand what that line in the accepted answer does, rewritten here for ease:</p>

<pre><code>from datetime import datetime

dt = datetime.strptime( date, '%Y-%m-%d %H:%M' )
dt_plus_25 = dt + datetime.timedelta( 0, 2*60*60 + 30*60 )
</code></pre>

<p>Unfortunately, even after reading the documentation I still do not understand how that line works.</p>

<p>What is the timedelta line doing? How does it work? </p>

<p>Additionally, before I found this stackoverflow post, I was working with time.struct_time tuples. I had a variable tm:</p>

<pre><code>tm  = time.strptime(...)
</code></pre>

<p>I was simply accessing the hour through tm.tm_hour and subtracting seven from it but this, for obvious reasons, does not work. This is why I am now trying to use datetime. tm now has the value</p>

<pre><code>tm = datetime.strptime(...)
</code></pre>

<p>I'm assuming using datetime is the best way to subtract seven hours?</p>

<p>Note: subtracting seven hours because I want to go from UTC to US/Pacific timezone. Is there a built-in way to do this?</p>
