comparison of time to time, where a is considered less than b when a precedes b in time. If one comparand is naive and the other is aware, TypeError is raised if an order comparison is attempted. For equality comparisons, naive instances are never equal to aware instances.
time
类使用tzinfo
进行比较和操作。例如,美国/太平洋地区的上午9:00不等于美国/东部的上午9:00。此外,如果将aware时间与naiver时间进行比较,例如,将美国/太平洋地区的上午9:00与“上午9:00”进行比较,python可能会引发类型错误来自the docs:
我发现它很有用,例如,如果我们处理的是同一时间发生的事件,而不考虑日期(例如,计划的作业),并且需要在不同的时区显示、操作和比较。在
如何获得TZ感知的
datetime.time
对象对于我的示例用例,我将使用}对象,它保存了
datetime.datetime.timetz()
从我的tz感知datetime.datetime
对象中提取{tzinfo
这将适合
datetime.time
对象,而不是也包含日期信息的datetime.datetime
对象。在你不能只用时间来转换
至于没有
time.astimezone()
的原因,我想可能是因为没有日期,就无法猜测DST转换和其他非固定UTC偏移的影响。在相关问题 更多 >
编程相关推荐