Why does Perl's POSIX::strftime %F specifier n

2020-07-06 04:27发布

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条回答
狗以群分
2楼-- · 2020-07-06 05:00

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.

查看更多
登录 后发表回答