:I use
import datetime
from datetime import datetime
from datetime import date
But then, if I use datetime
:
Example:
TimeNow = datetime.datetime.now()
It says that:
AttributeError: type object 'datetime.datetime' has no attribute 'datetime'
Can someone help me?
now()
is a function available in the datetime module of the datetime package. Hence to use it you can do either of the two:
from datetime import datetime
time_now = datetime.now()
or
import datetime
time_now = datetime.datetime.now()
In the second case, you need to access the datetime module inside the datetime package and then use the now() function.
You should either import datetime
and then call:
TimeNow = datetime.datetime.now()
or you can do:
from datetime import datetime
TimeNow = datetime.now()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.