%s
is not part of the C standard、取决于执行情况.在MacOS上,它有BSD根,它是.
%s is replaced by the number of seconds since the Epoch, UTC (see mktime(3)).
手册解释了…
标准
strftime()函数符合ISO/IEC 9899:1990("ISO C90"),并有许多扩展
包括'%C'、'%D'、' %E'、'% e'、'%G'、'% g'、'% h'、'% k'、'% l'、'% n'、'%O'、'%R'、'% r',
"% s"、"%T"、"% t"、"% u"、"%V"、"% z"和"%+".
"%G"、"% g"和"%V"替换中的特殊周数和年份在ISO 8601:1988中定义.
Epoch time是从epoch开始的数字101,所以是%s
.
如果我们看the first version of strftime.c in NetBSD,我们会看到这个.
188 1.1 mrg case 's':
189 1.1 mrg if (!_secs(t))
190 1.1 mrg return(0);
191 1.1 mrg continue;
_secs
换104只不过是mktime
左右的薄包装.C标准的人可能觉得%s
与mktime
是多余的,BSD的人认为它很方便.
许多用C实现的语言,如Python,仍然依赖于strftime
,因此只记录了标准语言和一些常见扩展.例如,在MacOS上的Python datetime.now().strftime("%:z")
中,简单地打印:z
,因为MacOS strftime
没有实现%:z
.而Ruby has its own strftime
implementation和Time.now.strftime('%:z')
是有效的.