为什么Perl的POSIX :: strftime%F说明符在Windows上不起作用? [英] Why does Perl's POSIX::strftime %F specifier not work on Windows?

查看:138
本文介绍了为什么Perl的POSIX :: strftime%F说明符在Windows上不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Mac :: PropertyList 模块的作者,该模块解析Apple属性列表格式.我已经设计出可以跨平台使用的功能,但是在使用 POSIX strftime函数时遇到了麻烦用于以Apple指定的格式创建日期字段.

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) );

在类似Unix的平台(包括darwin)上,此调用会产生正确的日期:

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

2013-09-23T12:34:56Z

在Windows上,它会产生:

On Windows, it produces:

T12:34:56Z

报告为 CPAN RT#83460 . Windows在这里发生了什么?

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

推荐答案

在我撰写此问题并研究所有内容时,我找到了自己的答案.我不希望所有的工作都浪费掉.

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.

我使用的%F格式不是可移植的,并且 POSIX 模块在其strftime条目中说:

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确实是%Y-%m-%d,所以我应该使用它.

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

我的特殊问题是,我知道 POSIX 模块会告诉您可以使用哪种格式说明符,但是我仍然必须查看strftime手册页以了解它们的作用.在查看手册页时,我忘记检查哪些是可移植的.

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.

这篇关于为什么Perl的POSIX :: strftime%F说明符在Windows上不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆