开发者

Where has now() moved in DateTime 2.12

开发者 https://www.devze.com 2023-02-25 07:15 出处:网络
I have a product which I\'m supporting which uses the now() method from the DateTime module. from DateTime import now

I have a product which I'm supporting which uses the now() method from the DateTime module.

from DateTime import now

However, in DateTime 2.1开发者_开发技巧2 this method no longer exists.

Has it been moved to a new location, or is there a new/preferred idiom for getting the current time?


From this page:

If the function is called with no arguments, then the current date/ time is returned, represented in the timezone of the local machine.

I browsed through the code of DateTime.py and I didn't see a now() method. So to answer your question, to get the current time just do a current = DateTime().


if you are referring to the build in datetime module, since at least python 2.5 now is a classmethod of the datetime class:

import datetime
datetime.datetime.now()


Zope's DateTime module never had a now() method - at least not since I am using Zope which dates back to the late 90s :-)

You are referring to datetime.now() of the Python standard library!?

0

精彩评论

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