相关疑难解决方法(0)

在Perl中获得UTC偏移的最佳方法是什么?

我需要在跨平台(Windows和各种Unix版本)方式中获取Perl中当前时区的UTC偏移量.它应符合以下格式:

zzzzzz,代表与UTC相关的±hh:mm

看起来我应该能够通过它strftime(),但它看起来并不一致.

Unix的:

Input: perl -MPOSIX -e "print strftime(\"%z\", localtime());"
Output: -0700
Run Code Online (Sandbox Code Playgroud)

视窗:

Input: perl -MPOSIX -e "print strftime(\"%z\", localtime());"
Output: Mountain Standard Time
Run Code Online (Sandbox Code Playgroud)

虽然看起来Unix给了我想要的东西(或者至少接近一些东西),但Windows却没有.我很确定我可以用Date::Time或者类似的方式来做,但是我真的希望不会因为我们广泛的安装基础而无法保证用户会有任何依赖.

我错过了一些明显的东西吗?提前致谢.

formatting perl timestamp

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

formatting ×1

perl ×1

timestamp ×1