Problem with strptime () -% p is ignored
source link: https://www.codesd.com/item/problem-with-strptime-p-is-ignored.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Problem with strptime () -% p is ignored
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 %I
in place of %H
.
You can refer to the manual here.
Related Articles
What is the problem with svn: ignore pattern?
Problem with IE overflow: automatic; And the web of Raphael is loaded in a DIV
Problem with Visual Studio 2008 Debugger
Delphi XE3: Problems with Complex Pre-Build Events
You do not know how to fix this problem with Java generics
Problems with Overload Operator []
Problem with date comparison in Oracle
JBCrypt serious problem with checkpw (returns true when it should not?)
Problem with getpwuid () and stat ()
Problem with 'StringVar' in the Python program
Problems with Rails 3 Active registration request interface with join on ID
Problem with increasing Java heap size in Eclipse
Cutting Problems with String Comparison
Azure: How to solve apt-get problems with Azure Ubuntu Archive?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK