<?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
?>
The AM
implies you are using a 12-hour clock . However, there is no "zero hour" in this clock system, so your first time example of 00:54:00 AM
is not a valid time (12-hour clock runs from one to twelve, then flips back to one with am/pm switched). Perhaps you meant just 00:54:00
(24-hour clock) or 12:54:00 AM/PM
(which would be six minutes before one o'clock).
You have passed AM in 24 hour time format.I have corrected it
$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 />';
if you're using a PHP version later than 5.3.0 you can use
http://www.php.net/manual/tr/function.date-parse-from-format.php
like
$a = 'MAY 05, 2001 00:54:00';
echo date('Y-m-d',date_parse_from_format("F d, Y H:i:s",$a)).'<br />';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.