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

上一篇: 我如何将Unix时间戳转换为DateTime,反之亦然?

下一篇: 如何将日期时间转换为日期(使用Python)?