In numpy 1.6.1, what's the most straightforward way to convert a datetime64
to a python datetime.datetime?  E.g. I have

In [1]: d = datetime64("2011-12-03 12:34:56.75")

In [2]: d
Out[2]: 2011-12-03 12:34:56.750000

I want the same time as a datetime.datetime instance.  My best hack so far
is to parse repr(d) with datetime.datetime.strptime:

In [3]: import datetime

In [4]: dt = datetime.datetime.strptime(repr(d), "%Y-%m-%d %H:%M:%S.%f")

In [5]: dt
Out[5]: datetime.datetime(2011, 12, 3, 12, 34, 56, 750000)

That works--unless there are no microseconds, in which case ".%f" must be
removed from the format string--but there must be a better way.

Warren
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to