I am trying to convert a date in a particular format using strptime, and i realized that the information about AM/PM is lost. Not sure 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 anybody tell me whats the purpose of having the %p specifier in strptime?
Thanks in advance,
AJ
The problem here is with
%H, which will read the hour in 24-hour format and ignore AM/PM. If you want to read the hour in 12-hour format and make use of AM/PM use%Iin place of%H.You can refer to the manual here.