Python 时间戳中的 T 和 Z 究竟是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29281935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What exactly does the T and Z mean in timestamp?
提问by roymustang86
I have this timestamp value being return by a web service "2014-09-12T19:34:29Z"
我有一个 Web 服务返回这个时间戳值 "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?
我正在尝试模拟这个网络服务,那么有没有办法strftime
在 python 中使用生成这个时间戳?
Sorry if this is painfully obvious, but Google was not very helpful and neither was the strftime()
reference page.
对不起,如果这很明显,但谷歌不是很有帮助,strftime()
参考页面也不是。
I am currently using this :
我目前正在使用这个:
x.strftime("%Y-%m-%dT%H:%M:%S%Z")
'2015-03-26T10:58:51'
采纳答案by Martijn Pieters
The T
doesn't really stand for anything. It is just the separatorthat the ISO 8601 combined date-time formatrequires. You can read it as an abbreviation for Time.
在T
并没有真正纳入什么。这仅仅是分隔的ISO 8601相结合的日期时间格式要求。您可以将其理解为Time的缩写。
The Z
stands for the Zerotimezone, as it is offset by 0 from the Coordinated Universal Time (UTC).
该Z
代表的零时区,因为它是由0从偏移协调世界时(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.
这两个字符都只是格式中的静态字母,这就是datetime.strftime()
方法没有记录它们的原因。您可以使用Q
orM
或,Monty Python
并且该方法也可以不变地返回它们;该方法仅查找以 开头的模式,%
并用来自datetime
对象的信息替换那些模式。