如何强制python打印numpy datetime64指定的时区? [英] How to force python print numpy datetime64 with specified timezone?

查看:579
本文介绍了如何强制python打印numpy datetime64指定的时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按照指定的时区查看numpy datetime64对象。

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

>>> import numpy as np
>>> np.datetime64('2013-03-10T01:30:54')
numpy.datetime64('2013-03-10T01:30:54+0400')
>>> np.datetime64('2013-03-10T01:30:54+0300')
numpy.datetime64('2013-03-10T02:30:54+0400')

即使我指定了另一个时区>> Python打印datetime对象始终为UTC + 0400(这是我的本地时区) ;> np.datetime64('2013-03-10T01:30:54 + 0300')。有没有办法通过UTC + 0000时区强制蟒蛇打印?

Python prints datetime objects always in UTC+0400 (it is my local timezone) even if I specify another timezone >>> np.datetime64('2013-03-10T01:30:54+0300'). Is there a way to force python print by UTC+0000 timezone?

我使用numpy 1.8.1。

I am using numpy 1.8.1 .

推荐答案

中提到了几次numpy文档


datetime对象代表一个时间。

The datetime object represents a single moment in time.

...

数据时间总是基于POSIX时间存储...

Datetimes are always stored based on POSIX time ...

所以,在内部,datetime64正在跟踪一个单一的整数,它表示自UNIX时代(1970-01-01)以来的一个值,而不是闰秒。

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.

因此,时区不会保留。如果您通过时区偏移量,则将其应用于确定正确的UTC时间。如果你不通过它,它将使用本地机器的时区。无论输入如何,在输出时,使用本地计算机的时区将UTC时间投影到具有偏移量的本地时间。

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.

这篇关于如何强制python打印numpy datetime64指定的时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆