問題描述
我有這個時間戳值由 Web 服務返回 "2014-09-12T19:34:29Z"
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?
我正在嘗試模擬這個網絡服務,那么有沒有辦法在 python 中使用 strftime
生成這個時間戳?
And I am trying to mock this web service, so is there a way to generate this timestamp using strftime
in python?
很抱歉,這很明顯,但 Google 并沒有提供多大幫助,strftime()
參考頁也沒有提供幫助.
Sorry if this is painfully obvious, but Google was not very helpful and neither was the strftime()
reference page.
我目前正在使用這個:
x.strftime("%Y-%m-%dT%H:%M:%S%Z")
'2015-03-26T10:58:51'
推薦答案
T
并不代表任何東西.它只是 ISO 8601 組合日期時間格式 所需的分隔符.您可以將其理解為 Time 的縮寫.
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.
Z
代表 Zero 時區,因為它從 協調世界時 (UTC).
The Z
stands for the Zero timezone, as it is offset by 0 from the Coordinated Universal Time (UTC).
這兩個字符都只是格式中的靜態字母,這就是 datetime.strftime()
方法沒有記錄它們的原因.您可以使用 Q
或 M
或 Monty Python
并且該方法也會將它們原封不動地返回;該方法僅查找以 %
開頭的模式,以用來自 datetime
對象的信息替換這些模式.
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.
這篇關于時間戳中的 T 和 Z 到底是什么意思?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!