php - 使用 strtotime 日期转到 1970 年代
php - using strtotime date goes to 1970s
我正在尝试使用 strttotime
获取给定日期的下一个 monday
,但我从 Jan 1970
获取日期作为输出。下面是我为下周一的获取日期编写的代码行,我从 获得了这段代码。谁能帮我理解为什么会这样。提前致谢。
代码:
$date_init = date('Y m d', strtotime('next monday', strtotime('2016 06 22')));
预期输出:
2016 06 27
实际输出:
1970 01 05
试试这个:
$date_init = date('Y m d', strtotime('next monday', strtotime('22-06-2016')));
'2016 06 22' 需要格式化为提到的格式之一 here
根据手册,字符串 2016 06 22
不是有效的日期格式。尝试添加连字符:
$date_init = date('Y m d', strtotime('next monday', strtotime('2016-06-22')));
您可以在此处找到所有有效的日期格式:http://php.net/manual/en/datetime.formats.date.php
2016 06 02
不是可接受的日期格式之一 as described in the PHP docs. For this reason, the inner call to strtotime
returns FALSE
as defined in the docs 以防无法解析给定的时间字符串。
由于这不是 $now
参数的外部 strtotime
的有效输入,它采用纪元或 1970 年 1 月 1 日作为其计算的基础.
因此,您得到的是 1970 年 1 月 1 日之后的下一个星期一。
从初始日期 字符串中删除空格将解决此问题:
$date_init = date('Y m d', strtotime('next monday', strtotime('20160622')));
我正在尝试使用 strttotime
获取给定日期的下一个 monday
,但我从 Jan 1970
获取日期作为输出。下面是我为下周一的获取日期编写的代码行,我从
代码:
$date_init = date('Y m d', strtotime('next monday', strtotime('2016 06 22')));
预期输出:
2016 06 27
实际输出:
1970 01 05
试试这个:
$date_init = date('Y m d', strtotime('next monday', strtotime('22-06-2016')));
'2016 06 22' 需要格式化为提到的格式之一 here
根据手册,字符串 2016 06 22
不是有效的日期格式。尝试添加连字符:
$date_init = date('Y m d', strtotime('next monday', strtotime('2016-06-22')));
您可以在此处找到所有有效的日期格式:http://php.net/manual/en/datetime.formats.date.php
2016 06 02
不是可接受的日期格式之一 as described in the PHP docs. For this reason, the inner call to strtotime
returns FALSE
as defined in the docs 以防无法解析给定的时间字符串。
由于这不是 $now
参数的外部 strtotime
的有效输入,它采用纪元或 1970 年 1 月 1 日作为其计算的基础.
因此,您得到的是 1970 年 1 月 1 日之后的下一个星期一。
从初始日期 字符串中删除空格将解决此问题:
$date_init = date('Y m d', strtotime('next monday', strtotime('20160622')));