You say you need to compare two time_t
values, ultimately. But how are you obtaining those values? If they are sent as strings, then Byron Whitlock's answer is plausible if your machine supports getdate()
. If they are already time_t
, then you can compare the time values. If you need to compare a time_t
generated locally with a string generated remotely, then you are caught between a rock and a hard place; you have to know somehow which ISO 8601 style is used when the data is sent.
Note that ISO 8601 expects that the two systems exchanging information will agree on the notation they are going to use, and in particular that they will agree on which fields can be left out (if any) and whether punctuation will separate the fields. If you know the (single) format, or can configure your system so that for each data source, you now the ISO 8601 format that will be used, then the POSIX strptime()
function can handle pretty much everything - though you need to know how your code is going to handle any undefined fields.
The title of the standard is, in full: "ISO 8601:2004 Data elements and interchange
formats — Information interchange —
Representation of dates and times". Its section §3.7 Mutual agreement says:
Some of the representations identified in this International Standard are only allowed by mutual agreement of
the partners in information interchange. Such agreement should ensure that fields in which the representation
may occur are not allowed to hold other representations that cannot be unambiguously distinguished from the
agreed representation.