Tom Anderson
Tom Anderson

Reputation: 47243

Can Boost Date Time Input/Output parse a date with an ordinal day of the month, like "January 2nd, 2024"?

I am using a library which delegates date formatting to Boost Date Time Input/Output, and i need to parse dates which look like "January 2nd, 2024".

The month and the year are easy enough, as are the spaces and comma.

The format specifier %e parses a day of the month, and copes with one or two digits, without requiring a leading zero or space. But it will apparently not trailing ordinal characters. I tried parsing the string

January 2nd, 2024

Using:

%B %e, %Y

And it comes out with a gibberish value.

Is there a way to parse dates like this? I would happily ignore the exact characters in the ordinal suffix, and so treat strings like:

January 2th, 2024

As valid.

Upvotes: 0

Views: 35

Answers (0)

Related Questions