问题:T和Z在时间戳中到底意味着什么?

我有这个时间戳值由Web服务返回 "2014-09-12T19:34:29Z"

我知道这意味着时区,但是那到底是什么意思呢?

而且我正在尝试模拟此Web服务,因此有没有办法strftime在python中使用生成此时间戳的方法?

很抱歉,如果这很明显,但Google的帮助不是很大,strftime()参考页面也没有。

我目前正在使用这个:

x.strftime("%Y-%m-%dT%H:%M:%S%Z")
'2015-03-26T10:58:51'

I have this timestamp value being return by a web service "2014-09-12T19:34:29Z"

I know that it means timezone, but what exactly does it mean?

And I am trying to mock this web service, so is there a way to generate this timestamp using strftime in python?

Sorry if this is painfully obvious, but Google was not very helpful and neither was the strftime() reference page.

I am currently using this :

x.strftime("%Y-%m-%dT%H:%M:%S%Z")
'2015-03-26T10:58:51'

回答 0

T并没有真正纳入什么。这仅仅是分隔ISO 8601相结合的日期时间格式要求。您可以将其阅读为Time的缩写。

Z代表的时区,因为它是由0从偏移协调世界时(UTC)

这两个字符都是格式上的静态字母,这就是为什么该datetime.strftime()方法未记录它们的原因。您可以使用QM或,Monty Python而该方法也可以将它们返回不变;该方法仅查找以开头的模式,%将其替换为来自datetime对象的信息。

The T doesn’t really stand for anything. It is just the separator that the ISO 8601 combined date-time format requires. You can read it as an abbreviation for Time.

The Z stands for the Zero timezone, as it is offset by 0 from the Coordinated Universal Time (UTC).

Both characters are just static letters in the format, which is why they are not documented by the datetime.strftime() method. You could have used Q or M or Monty Python and the method would have returned them unchanged as well; the method only looks for patterns starting with % to replace those with information from the datetime object.


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。