How can I get hour, minute, etc. From the numpy.datetime64 object?

Can I be blind or limited to find a smart solution, but I would like to extract the time for the numpy.datetime64 object and cannot find the obvious solution.

Of course I can do this:

import numpy as np
a = np.datetime64('2015-03-23T22:58')
print(a.tolist().time())

But that still leaves me with a timezone problem.

Also, I just have nothing to use numpy.datetime64 to convert it to datetime and use these methods. Or numpy.datetime64 lacks some basic functions / I do not use it for its intended purpose, and is it better to return to datetime.datetime?

+4
source share
1 answer

, ,

>>> import numpy as np
>>> a = np.datetime64('2015-03-23T17:00')  # 17hr local time
>>> b = np.datetime64('2015-03-23T17:00Z') # 17hr Zulu
>>> a
numpy.datetime64('2015-03-23T17:00-0400')
>>> b
numpy.datetime64('2015-03-23T13:00-0400')
>>> 
>>> a.tolist().time()
datetime.time(21, 0)
>>> b.tolist().time()
datetime.time(17, 0)
>>> 

.

+1

All Articles