如何从numpy.datetime64获取Unix时间戳
问题描述:
如何从numpy.datetime64或numpy.datetime_获取UNIX时间?
How do I get the UNIX time from a numpy.datetime64 or numpy.datetime_?
例如:
np.datetime_('2012-08-08 13:37:00')
答
对于numpy 1.6.1和1.7,我得到的np.datetime64('now')
值结果不一致.
I get inconsistent results for the value of np.datetime64('now')
on numpy 1.6.1 vs. 1.7.
这两种方法都适用:
>>> import datetime
>>> import numpy as np
>>> now = np.datetime64(datetime.datetime.now())
>>> (now.astype('uint64') / 1e6).astype('uint32')
1344447810