php日期()日期的数字描述


php date() numerical description of day

在php中使用哪个更安全/更好来获取一天的数字:

date('w'); // Numeric representation of the day of the week

date('N'); // From php manual: ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)

我喜欢第二个版本,因为它感觉更自然,但我想知道除了使用任何一种方法之外,是否还有其他含义?

这真的很琐碎,就像评论所说的那样,它不会影响你的项目。

发件人:http://php.net/manual/en/function.date.php

N-1(周一)至7(周日)

w-0(周日)至6(周六)

我能看到的唯一行为差异是,你做了一些算术运算,可能会被更改(比如从周日开始计算5天),或者数组算术(即数组索引为0),所以如果你使用"w",那么它可以用来访问数组的元素,比如"Sunday"(或者西班牙语等其他语言的Sunday)。

另一件需要考虑的事情是,如果你使用ISO标准,并且标准发生了变化,比如引入了一周中的新一天,那么PHP更有可能更新"N"并弃用"w"。