Question

I would like to know why the method now was implemented under the datetime.datetime label instead of the datetime.time?

For example to obtain today's date on python you do the following.

import datetime
print datetime.date.today()

but you can't the same for the time now, I mean

print datetime.time.now()

Instead you have to do the following:

print datetime.datetime.now()
Was it helpful?

Solution

"Now" is a point in time. That means date matters; if it's noon now, yesterday noon is not also now. (Time of day also matters; 9 AM today is also not now.) Thus, it makes sense to have a datetime.datetime.now, but not a datetime.time.now. It could make sense to have a datetime.time.currentlocaltime or datetime.time.currentutctime, but those methods don't exist. You could put in a feature request if you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top