如何在python中将datetime.date对象转换为datetime.datetime?

时间:2012-07-23 19:28:10

标签: python datetime date

  

可能重复:
  Convert a datetime.date object into a datetime.datetime object with zeros for any missing time attributes

如何将datetime.date obj转换为datetime.datetime obj,默认为午夜?

1 个答案:

答案 0 :(得分:23)

datetime.combine method使用空time instance

dateobject = datetime.date.today()
datetime.datetime.combine(dateobject, datetime.time())

或者,您可以使用datetime.time.min constant

datetime.datetime.combine(dateobject, datetime.time.min)

datetime.time()datetime.time.min都代表午夜(00:00:00)。