我需要將zope 2 DateTime對象轉換爲Python日期時間對象。什麼是最好的方式來做到這一點?謝謝,埃裏卡將zope DateTime對象轉換爲Python datetime對象的最佳方式是什麼?
8
A
回答
7
modernthingy = datetime.datetime.fromtimestamp(zopethingy.timeTime())
的datetime
實例時區,天真的;如果您需要支持時區(如Zope2的DateTime
),我推薦第三方擴展包pytz。
1
如果你的意思this一個
.strftime('%m/%d/%Y %H:%M') = 04/25/2005 10:19
然後反轉是
>>> time.strptime('04/25/2005 10:19','%m/%d/%Y %H:%M')
time.struct_time(tm_year=2005, tm_mon=4, tm_mday=25, tm_hour=10, tm_min=19, tm_sec=0, tm_wday=0, tm_yday=115, tm_isdst=-1)
10
較新的日期時間實現(2.11以上)具有asdatetime
方法,它返回一個python datetime.datetime實例:
modernthingy = zopethingy.asdatetime()
相關問題
- 1. 轉換爲DateTime對象
- 2. 轉換對象爲DateTime
- 3. 轉換JSON DateTime對象的JavaScript對象
- 4. 在Python中將對象轉換爲列表的最佳方式是什麼?
- 5. 將JSONObject轉換爲域對象的最佳方法是什麼?
- 6. C#將UTC int轉換爲DateTime對象
- 7. 將UTC時間轉換爲DateTime對象
- 8. 將字符串轉換爲DateTime對象
- 9. 將datetime轉換爲Date對象
- 10. 轉換成DateTime對象
- 11. 如何將timedelta對象轉換爲datetime對象
- 12. PHP:更換爲DateTime對象
- 13. 字符串轉換爲DateTime對象
- 14. 將XML轉換爲Java對象的最佳做法是什麼?
- 15. Python的需要DateTime對象轉換爲RFC 1132格式
- 16. 將地址對象轉換爲字符串的最佳方式是什麼?
- 17. 將對象數組轉換爲對象的最佳方法?
- 18. 從Datetime.ToFileTime()轉換爲DateTime對象
- 19. 轉換日期爲datetime對象蟒蛇
- 20. Python/postgres:將mxDateTime轉換爲內置datetime對象的優勢?
- 21. 如何將字符串轉換爲python中的datetime對象?
- 22. 如何將一個DateTime對象轉換爲python中的小時?
- 23. 將DateTime設置爲UTC的最佳方式是什麼?
- 24. datetime對象格式
- 25. 將日期格式化的字符串轉換爲DateTime對象?
- 26. 在Python(GAE)中將字符串轉換爲datetime對象?
- 27. 將字符串轉換爲datetime對象在Python
- 28. Python:如何將unixtimestamp和時區轉換爲datetime對象?
- 29. 如何將RFC822轉換爲python datetime對象?
- 30. 定製Zope對象的採購鏈的最佳方式是什麼?