3

Problem with strptime () -% p is ignored

 2 years ago
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.
neoserver,ios ssh client

Problem with strptime () -% p is ignored

advertisements

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?

I have the pattern svn:ignore datasheets/*/*.pdf It is supposed to ignore all pdfs that are at an arbitrary depth under multiple "datasheet" directories under the current root folder. As an example: say I have a dir structure like this Websites

Problem with IE overflow: automatic; And the web of Raphael is loaded in a DIV

I'm trying to place a Raphael canvas in to a div which is smaller than the actual canvas. So basically I have something like this: var paper = Raphael("test", 2000, 2000); var a = paper.rect(0, 0, 2000, 2000).attr({fill: "#000"}); // &

Problem with Visual Studio 2008 Debugger

I have a weird problem with Visual Studio 2008 in just one of my projects. When I set a break point on a line of code, it gets hit alright, but when I try to 'step over,' or whatever else that is supposed to pass over that break point and stop on the

Delphi XE3: Problems with Complex Pre-Build Events

We are currently in the process of switching from Delphi XE to Delphi XE3, and we are having serious problems with our pre-build-events. Our pre-build events look like this: SubWCRev "<SVN-Path>" "<InputFile>" VersionInfo.r

You do not know how to fix this problem with Java generics

So, I am trying to create a collection of Builders which can be applied to a collection of Specifications to build Stages. I am having a problem with adding my generic builders to a collection so that they can later be used in the building process. I

Problems with Overload Operator []

I've written the following code and run into a problem with overloading operator []. Here's the code for testmain.cpp: #include"test.hpp" int main() { C tab = C(15); bool b = tab[2]; return 0; } And here's the header file test.hpp: #ifndef _test

Problem with date comparison in Oracle

I am doing a date comparison in oracle. When I execute the code below select tr.x, tbi.y, to_char(tr.UPDATED_AT,'dd-mon-yyyy') from tbi, tb, tr where tbi.id=tb.id and tb.id=tr.id and tr.updated_at = to_date('23/02/2016', 'dd/MM/yyyy') No row is selec

JBCrypt serious problem with checkpw (returns true when it should not?)

EDIT: Ok so I've somewhat found an answer here BCrypt says long, similar passwords are equivalent - problem with me, the gem, or the field of cryptography? New question though, how can someone recommend using bCrypt for hashing if you have to limit t

Problem with getpwuid () and stat ()

I have the following code. It gives me a problem with free memory, but I haven't figured out what exactly the problem is. It seems that getpwuid(buf->st_uid); is not getting along with readdir(dirh); or with stat functions. Does anyone know why? buf

Problem with 'StringVar' in the Python program

I am trying to write a VERY simple UI in Python using Tkinter. I have run into a small problem with the StringVar class. The thing is, when I run the python script, I get an error on the line that initializes the StringVar variable. I have written a

Problems with Rails 3 Active registration request interface with join on ID

I have been having a problem with the Rails 3 Active Record Query Interface. I have a lookup table (lookups), a Main table (through_references), and a through/join table called through_tables. Thus this is a HABTM configuration that I have set up usi

Problem with increasing Java heap size in Eclipse

I have a problem with error saying ERROR: 'Java heap space'. I followed these instructions to increase the heap size for Eclipse, but it doesn't work. Eclipse seems to be ignoring the given values. My eclipse.ini file looks like this: -startup ../../

Cutting Problems with String Comparison

I have a problem with writing bash script. The problem is in comparison of strings. When I launch it, there's no errors. However in result, it is always changing the variable client. So if for an example we have two lines in file apple A orange D and

Azure: How to solve apt-get problems with Azure Ubuntu Archive?

On a new machine created with the 14.04LTS Azrue in the North Europe Datacenter, apt-get fails with the following issue: azureuser@x:~$ sudo apt-get update Err http://azure.archive.ubuntu.com trusty InRelease Err http://azure.archive.ubuntu.com trust

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK