首页 > 今天运行strftime("%G-%m-%d", time()) 的时候,会得到2015-12-31,这是为什么?

今天运行strftime("%G-%m-%d", time()) 的时候,会得到2015-12-31,这是为什么?

<?php


echo strftime("%G-%m-%d", time());


//得到2015-12-31

%G不是公历历法的年,而是按照ISO-8601:1988标准的年,是按周为单位计算的年


根据此种历法,每年第一个不少于4天(周1是一周的第一天)的周,视作第一周,少于4天则整个周视作上一年的最后一周

xelz's MacBook-Air: ~/tmp [12:21:18]
$ php -r 'error_reporting(0);echo strftime("%G-%V", strtotime("2014-12-28"))."\n";'
2014-52
xelz's MacBook-Air: ~/tmp [12:21:26]
$ php -r 'error_reporting(0);echo strftime("%G-%V", strtotime("2014-12-29"))."\n";'
2015-01

获得年份,应该使用 %y 或者 %Y

【热门文章】
【热门文章】