在php中的日期转换上显示不正确的结果 [英] Incorrect results showing on Date conversion in php

查看:63
本文介绍了在php中的日期转换上显示不正确的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$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?

推荐答案

您使用的是24小时制的上午/下午。上午/下午应该是12小时

you are using am/pm with 24 hours format. am/pm should be with 12 hr

12小时= 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小时= 00:30:45

$testTime   =   strtotime("2016-03-03 00:30:45");
$final      =   DATE("Y-m-d H:i",$testTime);//1970-01-01 01:00

这篇关于在php中的日期转换上显示不正确的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆