将 zope DateTime 对象转换为 Python datetime 对象的最佳方法是什么?

发布于 2024-08-27 21:35:51 字数 63 浏览 12 评论 0原文

我需要将 zope 2 DateTime 对象转换为 Python 日期时间对象。最好的方法是什么?谢谢,埃里卡

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ぺ禁宫浮华殁 2024-09-03 21:35:51

较新的 DateTime 实现(2.11 及更高版本)有一个 asdatetime 方法,该方法返回 python datetime.datetime 实例:

modernthingy = zopethingy.asdatetime()

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

modernthingy = zopethingy.asdatetime()
演出会有结束 2024-09-03 21:35:51
modernthingy = datetime.datetime.fromtimestamp(zopethingy.timeTime())

datetime 实例是 timezone-naive 的;如果您需要支持时区(如 Zope2 的 DateTime 那样),我推荐第三方扩展包 pytz

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.

べ繥欢鉨o。 2024-09-03 21:35:51

如果您的意思是 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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文