开发者

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

I need to convert a zope 2 Date开发者_JAVA技巧Time object into a Python datetime object. What is the best way to do that? Thanks, Erika


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

modernthingy = zopethingy.asdatetime()


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜