strptime 中的“p”代表什么?

问题描述 投票:0回答:10

许多语言库(C、Python、Ruby、PHP、PERL 等)中都有

strptime
函数。

它似乎基于 Open Group 的

time.h
规范。

我理解“str”代表字符串,“time”显然代表时间,但是“p”代表什么?解析?指针?打印?

每次我接触到 strptime() 函数时,我的大脑一片空白,必须在手册中查找该名称。我想如果我最终弄清楚它代表什么,也许我就有机会记住它。

strptime
10个回答
26
投票

我猜它代表“解析”,因为它的反向函数在Python的

strftime
模块中被称为
time
,其中“f”我可以合理地猜测代表“格式”。


15
投票

p = 指针。 它返回一个指向字符的指针。

顺便说一句,根据我的 K&R,有一个

char *strpbrk(cs,ct);

这个“p”也指返回的指针。


9
投票

大部分地方我都找到了

strftime() -> 字符串格式时间 &
strptime() -> 字符串解析时间


8
投票

我有同样的问题,我要使用 put:

strftime -> 'string from time'
strptime -> 'string, put time'

6
投票

它帮助我记住:

  • p 表示 product,str p 时间 -> 字符串 product 时间
  • f 表示格式,str f 时间 -> 字符串格式 时间

1
投票

我认为

strftime()
是来自时间的字符串。函数
strptime()
可能源自字符串解析时间。


0
投票

这是记住这一点的另一种方式:

f 代表 from,str f time (strftime)-> 字符串 from time

p 表示生产,str p time (strptime)-> 字符串生产时间


0
投票

我的助记词供大家参考:

strptime
= str 指向时间 = str -> 时间。

strftime
= 时间的 str = str <- time.


-1
投票

这是我发现有帮助的肺炎:

strftime
-> string (forward) time :此函数从 time 对象

进行转换

strptime
-> stringprevious)时间:此函数从 string 对象

进行转换

-1
投票

strftime:将日期时间格式化为字符串
strptime:parse将字符串转换为日期时间

© www.soinside.com 2019 - 2024. All rights reserved.