What is the best way to convert a zope DateTime object into Python datetime object?

强颜欢笑 提交于 2019-12-06 22:22:29

问题


I need to convert a zope 2 DateTime object into a Python datetime object. What is the best way to do that? Thanks, Erika


回答1:


modernthingy = datetime.datetime.fromtimestamp(zopethingy.timeTime())

The datetime instance is timezone-naive; if you need to support timezones (as Zope2's DateTime does), I recommend third-party extension package pytz.




回答2:


Newer DateTime implementations (2.11 and up) have a asdatetime method that returns a python datetime.datetime instance:

modernthingy = zopethingy.asdatetime()



回答3:


If you mean this one

.strftime('%m/%d/%Y %H:%M') =  04/25/2005 10:19

then reverse is

>>> 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)


来源:https://stackoverflow.com/questions/2578770/what-is-the-best-way-to-convert-a-zope-datetime-object-into-python-datetime-obje

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!