<p>How do I convert a datetime <em>string in local time</em> to a <em>string in UTC time</em>?</p>

<p>I'm sure I've done this before, but can't find it and SO will hopefully help me (and others) do that in future.</p>

<p><strong>Clarification</strong>:  For example, if I have <code>2008-09-17 14:02:00</code> in my local timezone (<code>+10</code>), I'd like to generate a string with the equivalent <code>UTC</code> time: <code>2008-09-17 04:02:00</code>.</p>

<p>Also, from <a href="http://lucumr.pocoo.org/2011/7/15/eppur-si-muove/" rel="noreferrer">http://lucumr.pocoo.org/2011/7/15/eppur-si-muove/</a>, note that in general this isn't possible as with DST and other issues there is no unique conversion from local time to UTC time.</p>

```
```
def local_to_utc(t):
    secs = time.mktime(t)
    return time.gmtime(secs)

def utc_to_local(t):
    secs = calendar.timegm(t)
    return time.localtime(secs)
```
```
Source:
http://feihonghsu.blogspot.com/2008/02/converting-from-local-time-to-utc.html
Example usage from
bd808
: If your source is a
```
datetime.datetime
```
object
```
t
```
, call as:
```
```
local_to_utc(t.timetuple())
```
```