Parsing an date/time string with std::get_time needs separators?

前端 未结 2 819
日久生厌
日久生厌 2020-12-20 17:18

Is a separator character required to parse a string using std::get_time? I can\'t find a reference to say that it is. I\'m trying to parse an ISO date/time string such as \"

2条回答
  •  鱼传尺愫
    2020-12-20 17:42

    The reference to the POSIX strptime() function in the standard is causing some confusion. The POSIX standard specifies that the conversion operators are separated by non-alpha characters.

    The application shall ensure that there is white-space or other non-alphanumeric characters between any two conversion specifications.

    The GLIBC version of strptime (and, IMO, any sane implementation) does not require these separators. [http://man7.org/linux/man-pages/man3/strptime.3.html -- see the Notes section.]

    Requiring separators makes it impossible to parse conforming ISO-8601 date/time basic formats. As C++ is also an ISO standard, its strptime() function should be able to parse this format.

    I think the std::get_time() documentation needs to be clarified to explicitly state that separators shall not be required and justify that statement by pointing to ISO-8601. It should further be clarified that the POSIX strptime() standard only specifies the conversion specifiers that are required to be supported by a conforming implementation.

提交回复
热议问题