문제

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