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!?
精彩评论