如何将datetime.date对象转换为time.struct_time对象?

Inc*_*ito 10 python time datetime

我有一个python脚本,我需要比较两个日期.我有一个列表日期作为time.struct_time对象,我需要与一些datetime.date对象进行比较.

如何将datetime.date对象转换为time.struct_time对象?或者我可以直接使用它们进行比较吗?

Luc*_*nes 14

尝试使用date.timetuple().从Python文档:

返回time.struct_time如返回的time.localtime().小时,分钟和秒为0,DST标志为-1.d.timetuple()相当于 time.struct_time((d.year, d.month, d.day, 0, 0, 0, d.weekday(), yday, -1)),yday = d.toordinal() - date(d.year, 1, 1).toordinal() + 1当前年份中的日期编号从1月1日开始为1.