用Python方式添加datetime.date和datetime.time对象


Answers:


354

python docs中

import datetime
datetime.datetime.combine(datetime.date(2011, 1, 1), 
                          datetime.time(10, 23))

退货

datetime.datetime(2011, 1, 1, 10, 23)

2
但是,这会丢失tzinfo(如果日期为1)。有办法保持吗?
ypercubeᵀᴹ

在Python 3中?找不到combine()
Olivier Pons,

@OlivierPons Python3中没有任何变化:docs.python.org/3/library/…–
eumiro

抱歉,您是对的,combine()可以应用于一个datetime值。非常感谢
Olivier Pons,
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.