问题
$testTime = strtotime("2016-03-03 07:40:45 pm");
echo "final=".$final = DATE("Y-m-d H:i",$testTime);//2016-03-03 19:40
Showing the correct out put But when ever I tried to change the hour to Zero
$testTime = strtotime("2016-03-03 00:30:45 am");
echo "final=".$final = DATE("Y-m-d H:i",$testTime);//1970-01-01 01:00
Incorrect values are showing.
Any idea?
回答1:
you are using am/pm with 24 hours format. am/pm should be with 12 hr
12 hour = 12:30:45 AM
$testTime = strtotime("2016-03-03 12:30:45 am");
$final = DATE("Y-m-d H:i",$testTime);//1970-01-01 01:00
24 hour = 00:30:45
$testTime = strtotime("2016-03-03 00:30:45");
$final = DATE("Y-m-d H:i",$testTime);//1970-01-01 01:00
回答2:
you are using am/pm with 24 hours format , Try this code
$testTime = strtotime("2016-03-03 12:30:45 am");
echo "final=".$final = DATE("Y-m-d H:i",$testTime);
来源:https://stackoverflow.com/questions/36125872/incorrect-results-showing-on-date-conversion-in-php