strtotime("fifth monday september 2017") returns “2017 年 10 月 2 日”?
strtotime("fifth monday september 2017") returns "2nd October, 2017"?
有谁知道如何让这个 return 错误?
9 月没有第 5 个星期一,所以这个函数 returns: 2017 年 10 月 2 日
date("jS F, Y", strtotime("fifth monday september 2017"));
PHP的strtotime
基于GNU的日期解析C函数(IIRC它实际上调用了这个C函数而不是使用它自己的实现)。来自 GNU documentation:
The explicit mention of a day of the week will forward the date (only if necessary) to reach that day of the week in the future... A number may precede a day of the week item to move forward supplementary weeks.
因此,使用您提供的示例,您不会直接从 strtotime
得到错误的结果。如果你想确认结果是在同一个月,你可以这样做:
$timestamp = strtotime("fifth monday september 2017");
$month = date('n', strtotime("september 1, 2017"));
$same_month = (date('n', $timestamp) === $month);
还有from the GNU documentation,补充一些观点:
Our units of temporal measurement, from seconds on up to months, are so complicated, asymmetrical and disjunctive so as to make coherent mental reckoning in time all but impossible... Unlike the more successful patterns of language and science, which enable us to face experience boldly or at least level-headedly, our system of temporal calculation silently and persistently encourages our terror of time... It is no wonder then that we often look into our own immediate past or future, last Tuesday or a week from Sunday, with feelings of helpless confusion.
-Robert Grudin, Time and the Art of Living
有谁知道如何让这个 return 错误?
9 月没有第 5 个星期一,所以这个函数 returns: 2017 年 10 月 2 日
date("jS F, Y", strtotime("fifth monday september 2017"));
PHP的strtotime
基于GNU的日期解析C函数(IIRC它实际上调用了这个C函数而不是使用它自己的实现)。来自 GNU documentation:
The explicit mention of a day of the week will forward the date (only if necessary) to reach that day of the week in the future... A number may precede a day of the week item to move forward supplementary weeks.
因此,使用您提供的示例,您不会直接从 strtotime
得到错误的结果。如果你想确认结果是在同一个月,你可以这样做:
$timestamp = strtotime("fifth monday september 2017");
$month = date('n', strtotime("september 1, 2017"));
$same_month = (date('n', $timestamp) === $month);
还有from the GNU documentation,补充一些观点:
Our units of temporal measurement, from seconds on up to months, are so complicated, asymmetrical and disjunctive so as to make coherent mental reckoning in time all but impossible... Unlike the more successful patterns of language and science, which enable us to face experience boldly or at least level-headedly, our system of temporal calculation silently and persistently encourages our terror of time... It is no wonder then that we often look into our own immediate past or future, last Tuesday or a week from Sunday, with feelings of helpless confusion.
-Robert Grudin, Time and the Art of Living