How to force python print numpy datetime64 with specified timezone?

前端 未结 3 978
孤城傲影
孤城傲影 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:53

    Mentioned a few times in the numpy documentation:

    The datetime object represents a single moment in time.

    ...

    Datetimes are always stored based on POSIX time ...

    So, internally a datetime64 is tracking a single integer, which represents a moment in time as a value since the UNIX epoch (1970-01-01) - not counting leap seaconds.

    Therefore, time zones are not preserved. If you pass in a time zone offset, it will apply it to determine the correct UTC time. If you don't pass one, it will use the local machine's time zone. Regardless of input, on output it uses the local machine's time zone to project the UTC time to a local time with offset.

提交回复
热议问题