How to force python print numpy datetime64 with specified timezone?

前端 未结 3 982
孤城傲影
孤城傲影 2021-02-13 23:40

I want to see numpy datetime64 objects by my specified timezone.

>>> import numpy as np
>>> np.datetime64(\'2013-03-10T01:30:54\')
numpy.dateti         


        
3条回答
  •  南方客
    南方客 (楼主)
    2021-02-13 23:47

    Is there a way to force python print by UTC+0000 timezone?

    You could call .item() that returns a naive datetime object that represents time in UTC on data in your example:

    >>> import numpy
    >>> numpy.__version__
    '1.8.1'
    >>> dt = numpy.datetime64('2013-03-10T01:30:54+0300')
    >>> dt
    numpy.datetime64('2013-03-10T02:30:54+0400')
    >>> dt.item()
    datetime.datetime(2013, 3, 9, 22, 30, 54)
    >>> print(dt.item())
    2013-03-09 22:30:54
    

提交回复
热议问题