now()在DateTime 2.12中移动的位置

sie*_*ebo 2 python datetime

我有一个我支持的产品,它使用DateTime模块中的now()方法.

from DateTime import now
Run Code Online (Sandbox Code Playgroud)

但是,在DateTime 2.12中,此方法不再存在.

是否已将其移至新位置,或者是否有新的/首选习惯用于获取当前时间?

gla*_*xly 9

这个页面:

如果在没有参数的情况下调用该函数,则返回当前日期/时间,以本地计算机的时区表示.

我浏览了DateTime.py的代码,但没有看到now()方法.所以要回答你的问题,要获得当前时间,只需做一个current = DateTime().


kep*_*pla 6

如果你指的是datetime模块中的build,那么至少python 2.5 now是类的datetime类方法:

import datetime
datetime.datetime.now()
Run Code Online (Sandbox Code Playgroud)