php strtotime return 1970-01-01


php strtotime return 1970-01-01

<?php
$a = 'MAY 05, 2001  00:54:00 AM';
echo date('Y-m-d',strtotime($a)).'<br />';
$b = 'MAY 05, 2001  05:54:00 AM';
echo date('Y-m-d',strtotime($b)).'<br />';
//MAY 05, 2001  00:54:00 AM return 1970-01-01
//MAY 05, 2001  05:54:00 AM return 2001-05-05
?>

AM表示您使用的是12小时时钟。但是,此时钟系统中没有"零时",因此00:54:00 AM的第一个时间示例不是有效时间(12小时时钟从1运行到12,然后在am/pm切换的情况下翻转回1)。也许你的意思只是00:54:00(24小时时钟)或12:54:00 AM/PM(1点前6分钟)。

您已经通过了24小时时间格式的AM。我已经纠正了

$a = 'MAY 05, 2001 00:54:00';
echo date('Y-m-d',strtotime($a)).'<br />';
$b = 'MAY 05, 2001  05:54:00 AM';
echo date('Y-m-d',strtotime($b)).'<br />';

如果您使用的是5.3.0之后的PHP版本,则可以使用

http://www.php.net/manual/tr/function.date-parse-from-format.php

$a = 'MAY 05, 2001 00:54:00';
echo date('Y-m-d',date_parse_from_format("F d, Y H:i:s",$a)).'<br />';