title: Converting between datetime, Timestamp and datetime64
body: <p>How do I convert a <code>numpy.datetime64</code> object to a <code>datetime.datetime</code> (or <code>Timestamp</code>)?</p>
  
  <p>In the following code, I create a datetime, timestamp and datetime64 objects.</p>
  
  <pre><code>import datetime
  import numpy as np
  import pandas as pd
  dt = datetime.datetime(2012, 5, 1)
  # A strange way to extract a Timestamp object, there's surely a better way?
  ts = pd.DatetimeIndex([dt])[0]
  dt64 = np.datetime64(dt)
  
  In [7]: dt
  Out[7]: datetime.datetime(2012, 5, 1, 0, 0)
  
  In [8]: ts
  Out[8]: &lt;Timestamp: 2012-05-01 00:00:00&gt;
  
  In [9]: dt64
  Out[9]: numpy.datetime64('2012-05-01T01:00:00.000000+0100')
  </code></pre>
  
  <p><em>Note: it's easy to get the datetime from the Timestamp:</em></p>
  
  <pre><code>In [10]: ts.to_datetime()
  Out[10]: datetime.datetime(2012, 5, 1, 0, 0)
  </code></pre>
  
  <p>But how do we extract the <code>datetime</code> or <code>Timestamp</code> from a <code>numpy.datetime64</code> (<code>dt64</code>)?</p>
  
  <p>.</p>
  
  <p>Update: a somewhat nasty example in my dataset (perhaps the motivating example) seems to be:</p>
  
  <pre><code>dt64 = numpy.datetime64('2002-06-28T01:00:00.000000000+0100')
  </code></pre>
  
  <p>which should be <code>datetime.datetime(2002, 6, 28, 1, 0)</code>, and not a long (!) (<code>1025222400000000000L</code>)...</p>