2

How to tell Numpy to print datetime64 in UTC and not in local timezone?

For example, I get:

>>> np.datetime64('2012-01-01T00:00Z')
Out[111]: numpy.datetime64('2012-01-01T02:00+0200')

But I prefer to get:

>>> np.datetime64('2012-01-01T00:00Z')
Out[110]: numpy.datetime64('2012-01-01T00:00+0000')
4

1 回答 1

0

部分解决方案:

>>> np.set_printoptions(formatter={'datetime':np.datetime_as_string})
>>> print np.array(['2012-01-02T01:02Z'], dtype='datetime64')
[2012-01-02T01:02Z]

唯一的问题是标量仍以本地时区打印:

>>> print np.array(['2012-01-02T01:02Z'], dtype='datetime64')[0]
2012-01-02T03:02+0200
于 2012-10-30T22:51:16.517 回答