So, the answer given is almost correct but ISO 6801 dates are a little more complex than that. In essence, an ISO 6801 string consists of three distinct parts, date, time, and timezone. These are all valid representations of the same date and time:
2023-07-10T10:11:12Z
2023W281T9:11:12-1
2023190T114112+1:30
More specifically, the standard specifies three distinct parts that all may or may not exist. First, the date may be written as one of:
CC
(1st of Jan, CC00)
YYYY
(1st of Jan, YYYY)
YYYY-MM
(1st of MM, YYYY)
YYYYMMDD
or YYYY-MM-DD
(DD of MM, YYYY)
YYYYWww
or YYYY-Www
(Monday, Week ww, YYYY)
YYYYWwwD
or YYYY-Www-D
(day D of Week ww, YYYY)
YYYYDDD
or YYYY-DDD
(Day DDD of YYYY)
All of the above are valid dates. Optionally, one may also supply a time with the T prefix. Note millihours, which is 3600 milliseconds per millihour, and milliminutes, which is 60 milliseconds per milliminute.
Thh
(hh:00:00)
Thhmm
or Thh:mm
(hh:mm:00)
Thhmmss
or Thh:mm:ss
(hh:mm:ss)
Thh.hhh
(hh:00:00 + hhh millihours)
Thhmm.mmm
or Thh:mm.mmm
(hh:mm:00 + mmm milliminutes)
Thhmmss.sss
or Thh:mm:ss.sss
(hh:mm:ss + sss milliseconds)
And of course, in order to complicate things further, the world also has time zones. This is added with either a Z (UTC time), or +, or - corrections. So, again, here are the valid extensions:
Z
(UTC time)
+hh
(Offset by hh hours before UTC time)
-hh
(Offset by hh hours after UTC time)
+hhmm
or +hh:mm
(Offset by hh hours and mm minutes before UTC time)
-hhmm
or -hh:mm
(Offset by hh hours and mm minutes after UTC time)
It sure would be convenient to have a function handy that would validate these specific expressions and nothing else for a proper time output. To my knowledge no proper STL implementation exists of this standard, though I do make the argument there should be one that then outputs a proper std::chrono timepoint. That does not solve the current problem though, so for now... Use std::chrono as the backend and make it yourself! :)