TL; DR; use a string with the appropriate encoding if there is no reason for this.
It depends on what is required. Here are some differences - keep in mind that modern computers are fast, and conversion probably only accounts for a small fraction of the total application time, so “big processing” usually cannot be measurable!
String (with ISO 8601 or more stringent XML dateTime ):
- "more space" / "more processing" (see above) / fixed size or variable size
- standardized cultural neutral format
- easy to read and easily identifiable
- supports time zones
- more range (-9999 to 9999)
- greater / arbitrary accuracy (up to 1us)
- lexicographically ordered (in the same time zone and compatible format)
Age (UNIX variant):
- "less space" / "less processing" / fixed size
- standardized neutral neutral format
- not readable by humans (a conscientious coder should be able to identify "now")
- no timezones (cannot even distinguish between "local" and UTC)
- smaller range (from 1970 to 2034 with a signed 32-bit number)
- less / fixed accuracy (1 second)
- numerical ordering
( Julian Day is another encoding with many similarities to the time of the era.)
Conclusion:
If space / performance is not a proven issue, this requires performance analysis and functional requirements - I would choose the first one. Today computers are a little faster than computers just a few years ago, and much, much faster than computers decades ago.
user166390
source share