Get UTC timestamp from time zone aware datetime object in Python
<p>I have a datetime object that I created with<code>datetime.datetime(year, month, day, hour, minute, tzinfo=pytz.timezone('US/Pacific'))</code>.
Please correct me if I'm wrong, but I believe that my datetime object is NOT naÃ¯ve. How do I convert this datetime object to a UTC timestamp?</p>

<p>Use <code>datetime.astimezone</code> to get the same datetime in UTC (or any other timezone).</p>

<pre><code>dt = datetime.datetime(year, month, day, hour, minute, tzinfo=pytz.timezone('US/Pacific'))
dt_utc = dt.astimezone(pytz.timezone('UTC'))
</code></pre>

python datetime utc