Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
一个比另一个更受欢迎吗?如果是这样,在所有情况下还是仅在少数情况下?
我打算使用某种形式的日期类来保存很长的日期和时间数据列表,例如'2009-01-01 10:12:00'.
'2009-01-01 10:12:00'
struct_time 是表示时间的旧方式,仿照 C 标准库。datetime 来得较晚,比 struct_time 函数更pythonic,更有特色,并且在边缘情况下具有更可预测的行为。我会使用 datetime ,除非在极少数情况下测量的性能差异足够重要,或者它使代码的可读性显着降低。
datetime更面向对象并提供许多方便的功能,例如使用timedelta-objects 的算术运算。
datetime
timedelta