Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the "p" in strptime stand for?

Tags:

strptime

There is a strptime function in many language libraries (C, Python, Ruby, PHP, PERL, etc.).

It seems to be based on the Open Group's specification for time.h.

I understand 'str' stands for string, and 'time' obviously stands for time, but what does the 'p' stand for? Parse? Pointer? Print?

Every time I reach for the strptime() function, I have a mental blank, and have to look up the name in a manual. I figure if I finally worked out what it stood for, perhaps I would have a chance of remembering it.

like image 924
Oddthinking Avatar asked Sep 04 '12 02:09

Oddthinking


People also ask

What is the use of Strptime in Python?

The strptime() function in Python is used to format and return a string representation of date and time. It takes in the date, time, or both as an input, and parses it according to the directives given to it. It raises ValueError if the string cannot be formatted according to the provided directives.

What is Strptime and Strftime?

You might want to use these where times are irrelevant. strptime is short for "parse time" where strftime is for "formatting time". That is, strptime is the opposite of strftime though they use, conveniently, the same formatting specification.

How do you parse a string time in python?

Python time method strptime() parses a string representing a time according to a format. The return value is a struct_time as returned by gmtime() or localtime().


3 Answers

I guess it stands for "parse" because its reverse function is called strftime in Python's time module wherein the "f" I can reasonably guess stands for "format".

like image 59
an0 Avatar answered Oct 01 '22 13:10

an0


p = pointer. It returns a pointer to a char.

BTW According to my K&R there is a

char *strpbrk(cs,ct);

This 'p' also refers to the returned pointer.

like image 26
Phillip Ngan Avatar answered Oct 01 '22 12:10

Phillip Ngan


I have same problem and I'm going with put:

strftime -> 'string from time'
strptime -> 'string, put time'
like image 8
kztd Avatar answered Oct 01 '22 13:10

kztd