How do I convert datetime to date (in Python)?
如何将datetime.datetime
对象(例如, datetime.datetime.now())
的返回值datetime.datetime.now())
转换为Python中的datetime.date
对象?
使用date()
方法:
datetime.datetime.now().date()
From the documentation:
datetime.datetime.date()
Return date object with same year, month and day.
You use the datetime.datetime.date()
method:
datetime.datetime.now().date()
Obviously, the expression above can (and should IMHO :) be written as:
datetime.date.today()
链接地址: http://www.djcxy.com/p/25192.html