我在哪裏可以找到建立RFC 3339時間的例程?Python和RFC 3339時間戳
2
A
回答
1
這是基於RFC第10頁上的例子。唯一的區別是我顯示的是六位數的微秒值,與Google雲端硬盤的時間戳一致。
from math import floor
def build_rfc3339_phrase(datetime_obj):
datetime_phrase = datetime_obj.strftime('%Y-%m-%dT%H:%M:%S')
us = datetime_obj.strftime('%f')
seconds = datetime_obj.utcoffset().total_seconds()
if seconds is None:
datetime_phrase += 'Z'
else:
# Append: decimal, 6-digit uS, -/+, hours, minutes
datetime_phrase += ('.%.6s%s%02d:%02d' % (
us,
('-' if seconds < 0 else '+'),
abs(int(floor(seconds/3600))),
abs(seconds % 3600)
))
return datetime_phrase
0
python-rfc3339對我很好。
0
rfc3339非常靈活 - http://www.ietf.org/rfc/rfc3339.txt - 它有效地定義了一大堆格式。您可以生成幾乎所有的人只使用Python標準時間格式化 - http://docs.python.org/3.3/library/datetime.html#strftime-strptime-behavior
然而,有一個怪胎,那就是它們允許(這是可選)在數字時區偏移小時和分鐘之間的:
(%z
) 。 python不會顯示,所以如果你想包括你需要python-rfc3339或類似的。
for 解析 rfc3339,簡單日期將處理所有格式。但由於它使用python打印例程,因此無法處理上述的:
情況。
相關問題
- 1. 輸出RFC 3339 Java中的時間戳
- 2. rfc 3339時間戳格式無效?
- 3. RFC 3339使用時間戳解碼ř
- 4. 將RFC 3339時間轉換爲標準Python時間戳
- 5. 生成類似於Google Tasks API的RFC 3339時間戳?
- 6. 如何在TCL中創建RFC 3339時間戳?
- 7. C#日期時間 - RFC 3339格式
- 8. 如何按照RFC 3339
- 9. RFC 3339,以DD.MM.YYYY格式
- 10. 轉換日期與RFC 3339中定義的時間偏移到PHP中的時間戳
- 11. 解析日期IETF RFC 3339在php
- 12. 如何使用pa ++解析日期時間並將其轉換爲RFC 3339?
- 13. Python unix時間戳轉換和時區
- 14. 如何在Python中將RFC 822時間戳轉換爲可讀格式?
- 15. 將RFC 1123日期轉換爲PHP中的時間戳
- 16. 從日期時間到時間戳python
- 17. tcpreplay和時間戳
- 18. Mercurial和時間戳
- 19. 插入時間戳在python
- 20. 模糊時間戳與Python
- 21. Python中的NTP時間戳
- 22. 轉換時間戳在Python
- 23. python:來自pytz本地時間戳的UTC時間戳
- 24. 時間戳問題:Python無法識別時間戳
- 25. python函數在時間戳範圍中生成時間戳
- 26. 在Python轉換時間戳UNIX時間戳
- 27. 轉換的PostgreSQL時間戳爲JavaScript時間戳在Python
- 28. Python:將Varbinary類型的時間戳轉換爲unix時間戳
- 29. python linux時間戳到日期時間和反向
- 30. 可視化時間戳和累計時間使用python