开发者

What are the differences between struct_time and datetime?

开发者 https://www.devze.com 2023-01-07 03:02 出处:网络
Is one preferred over the other? If so, in all cases or just a few? I am intending to use some form of date class f开发者_运维知识库or keeping long lists of date and time data, e.g. \'2009-01-01 10:1

Is one preferred over the other? If so, in all cases or just a few?

I am intending to use some form of date class f开发者_运维知识库or keeping long lists of date and time data, e.g. '2009-01-01 10:12:00'.


struct_time is the old way of representing times, modeled after the C standard library. datetime came later, is more pythonic, is more featureful, and has more predictable behavior in edge cases than the struct_time functions. I would use datetime except in the rare cases where a measured performance difference is significant enough to matter, or where it makes the code significantly less readable.


datetime is more object oriented and offers many convenient features, e.g. arithmetic with timedelta-objects.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号