为什么date_parse
无法识别字符串中的年份?
<?php
$string = "Saturday, 23 March, 2013";
print_r(date_parse($string));
?>
结果,
Array
(
[year] =>
[month] => 3
[day] => 23
[hour] => 20
[minute] => 13
[second] => 0
[fraction] => 0
[warning_count] => 0
[warnings] => Array
(
)
[error_count] => 0
[errors] => Array
(
)
[is_localtime] =>
[relative] => Array
(
[year] => 0
[month] => 0
[day] => 0
[hour] => 0
[minute] => 0
[second] => 0
[weekday] => 6
)
)
答案 0 :(得分:4)
看起来格式不正确。当你执行以下操作时,它会返回正确的年份。
$string = "Saturday, 23 March, 2013";
^ //no comma here, should be just 23 March 2013
supported formats中的任何地方都可以看到Date-string和time-string的所有组件都有相同的分隔符。
答案 1 :(得分:0)
您也可以尝试使用strtotime()。这是一个了不起的功能,可以处理各种各样的输入 - 甚至是“3天前”的相对输入。