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

WBOY
Release: 2016-06-06 20:39:42
Original
1044 people have browsed it

<code><?php echo strftime("%G-%m-%d", time());


//得到2015-12-31
</code></code>
Copy after login
Copy after login

回复内容:

<code><?php echo strftime("%G-%m-%d", time());


//得到2015-12-31
</code></code>
Copy after login
Copy after login

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

今天运行strftime(
今天运行strftime(

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

<code>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
</code>
Copy after login

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

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template