Problem with strptime () -% p is not taken into account

I am trying to convert a date in a specific format using strptime, and I realized that the AM / PM information is lost. I do not know why.

Here is the code.

struct tm t;
strptime("Wed 4/18/2007 4:28:22 PM", "%a %m/%d/%Y %H:%M:%S %p", &t);
std::cout<<t.tm_hour<<endl;
strptime("Wed 4/18/2007 4:28:22 AM", "%a %m/%d/%Y %H:%M:%S %p", &t);
std::cout<<t.tm_hour<<endl;

Can someone tell me why the specifier is needed %pin strptime?

Thanks in advance, AJ

+3
source share
2 answers

The problem here is %Hthat it will read the hour in 24 hour format and ignore AM / PM. If you want to read the hour in 12-hour format and use AM / PM, use %Iinstead %H.

.

+5

:

% p = m.m p.m.

0

Source: https://habr.com/ru/post/1758329/


All Articles