Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between struct_time and datetime?

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 for keeping long lists of date and time data, e.g. '2009-01-01 10:12:00'.

like image 981
c00kiemonster Avatar asked Jul 13 '10 07:07

c00kiemonster


2 Answers

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.

like image 162
ʇsәɹoɈ Avatar answered Sep 26 '22 17:09

ʇsәɹoɈ


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

like image 31
Björn Pollex Avatar answered Sep 25 '22 17:09

Björn Pollex