Why can’t I just do datetime.now()? Python doesn’t like this?? Whats the correct why to import and use the datetime library in python…?
import datetime
now = datetime.datetime.now()
print "Time: %d:%02d - Date: %d/%d/%d <br>" %(now.hour, now.minute, now.month, now.day, now.year)
That’s because you are importing the datetime module (which contains classes for manipulating dates and times as stated in the documentation) not the datetime object. In such classes and objects inside the datetime module exists an object named datetime (yes, the same name as the module where it lives), so to use the datetime object the way you want you need to import it like this: