你想要%Y,並不%G。 %G旨在與%V一起使用以顯示ISO 8601星期編號,該編號可能在年初之前開始或在結束之後結束。
例子:
use POSIX 'strftime';
print strftime("%Y-%m-%d week %G-%V\n",0,0,0,$_,11,111) for 25..31;
print strftime("%Y-%m-%d week %G-%V\n",0,0,0,$_,0,112) for 1..9;
輸出:
2011-12-25 week 2011-51
2011-12-26 week 2011-52
2011-12-27 week 2011-52
2011-12-28 week 2011-52
2011-12-29 week 2011-52
2011-12-30 week 2011-52
2011-12-31 week 2011-52
2012-01-01 week 2011-52
2012-01-02 week 2012-01
2012-01-03 week 2012-01
2012-01-04 week 2012-01
2012-01-05 week 2012-01
2012-01-06 week 2012-01
2012-01-07 week 2012-01
2012-01-08 week 2012-01
2012-01-09 week 2012-02
愚蠢的ISO 8601。謝謝!將它更改爲%Y固定它! – 2014-12-08 09:41:30