0

我正在尝试转换datetime为,numpy.datetime64但以下情况失败:

>>> import numpy as np
>>> from datetime import datetime
>>> np.datetime64(datetime.max)
OSError: Failed to use 'localtime_s' to convert to a local time

我认为datetime64无法处理如此遥远的时间戳。

那么datetime64可以处理的最大时间戳是多少呢?

4

1 回答 1

2

Depends on what the specified unit of your np.datetime64 object is (according to the numpy docs). Since you have given a timestamp with microseconds the allowed range is [290301 BC, 294241 AD].

This answered your question but I think the unspoken other question is why it throws an Exception:

I'm facing the same error (using Windows) and I tried a=np.datetime64(datetime.max) which works. Therefore I suspect the problem is NOT the np.datetime64 span (because creating such a datetime works) but that the __repr__ requires the OS in some way and probably the OS limits it in your case. So check what's the maximum localtime of your OS and for every datetime after that you can still work with the np.datetime64 objects but cannot print them on screen. :-)

于 2016-02-15T19:50:27.937 回答