Incorrect results showing on Date conversion in php

不想你离开。 提交于 2019-12-12 03:28:19

问题


$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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!