Why does Perl's POSIX::strftime %F specifier not work on Windows?

ぐ巨炮叔叔 提交于 2020-01-01 08:43:02

问题


I'm the author of the Mac::PropertyList module which parses the Apple property list format. I've designed this to work across platforms, but I'm having trouble with POSIX's strftime function which I use to create the date fields in the format that Apple specifies.

use POSIX; 
print 'Epoch is: ' . POSIX::strftime( "%FT%H:%M:%SZ\n", gmtime(978307200) );

On unix-like platforms, including darwin, this call produces the right sort of date:

2013-09-23T12:34:56Z

On Windows, it produces:

T12:34:56Z

This was reported as CPAN RT #83460. What's going on with Windows here?


回答1:


As I was writing this question and researching everything, I found my own answer. I don't want all that work to go to waste though.

The %F format I used is not portable, and the POSIX module says in its strftime entry:

If you want your code to be portable, your format ("fmt")
argument should use only the conversion specifiers defined by
the ANSI C standard (C89, to play safe).  These are
"aAbBcdHIjmMpSUwWxXyYZ%".

%F is really %Y-%m-%d, so I should use that.

My particular problem is that I know that the POSIX module tells you which format specifiers you can use to be portable, but I still have to look at the strftime man page to see what they do. In looking at the man page, I forget to check which ones are portable.



来源:https://stackoverflow.com/questions/18970859/why-does-perls-posixstrftime-f-specifier-not-work-on-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!