Why method now in Python is obtained as datetime.datetime.now instead of datetime.time.now?

StackOverflow https://stackoverflow.com/questions/18217550

Вопрос

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()
Это было полезно?

Решение

"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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top