php 将字符串转换为年份中的时间问题
php converting string to time issue in year
我正在尝试在 php
中将字符串转换为时间 strtotime
操作
这是我的代码
echo date("Y-m-d", strtotime('2 January, 2017'));
当我为 2 January, 2016
进行转换时,结果为 2016-01-02
但是当我为 2 January, 2017
进行转换时,结果为 2016-01-02
,预期为 2017-01-02
代码中有什么问题,我该如何解决?请帮忙
改用DateTime::createFromFormat
:
$date = DateTime::createFromFormat('d F, Y', '2 January, 2017');
echo $date->format('Y-m-d');
strtotime
无法读取 2 January, 2017
。 2 January, 2016
产生正确的结果只是因为是当年。在这种情况下 2 January, 2016
=== 2 January
.
我正在尝试在 php
中将字符串转换为时间strtotime
操作
这是我的代码
echo date("Y-m-d", strtotime('2 January, 2017'));
当我为 2 January, 2016
进行转换时,结果为 2016-01-02
但是当我为 2 January, 2017
进行转换时,结果为 2016-01-02
,预期为 2017-01-02
代码中有什么问题,我该如何解决?请帮忙
改用DateTime::createFromFormat
:
$date = DateTime::createFromFormat('d F, Y', '2 January, 2017');
echo $date->format('Y-m-d');
strtotime
无法读取 2 January, 2017
。 2 January, 2016
产生正确的结果只是因为是当年。在这种情况下 2 January, 2016
=== 2 January
.