<?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
?>
答案 0 :(得分:3)
AM
表示您使用的是12-hour clock。但是,此时钟系统中没有“零小时”,因此您的第一次00:54:00 AM
示例不是有效时间(12小时时钟从1到12运行,然后翻转到上午/下午1)切换)。也许你的意思是00:54:00
(24小时制)或12:54:00 AM/PM
(这将是一点前六分钟)。
答案 1 :(得分:2)
你已经以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 />';
答案 2 :(得分:0)
如果您使用的是晚于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 />';