new DateTime('2016-04-01 00:00:00')返回'04-04-01 12:00:00 [英] new DateTime('2016-04-01 00:00:00') returns '2016-04-01 12:00:00

查看:96
本文介绍了new DateTime('2016-04-01 00:00:00')返回'04-04-01 12:00:00的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个没有脑子,但我看不到解决方案。我有以下代码:

This is probably a no-brainer, but I can't see the solution. I have the following code:

$begin = new DateTime('2016-03-14 00:00:00');
echo $begin->format('Y-m-d h:i:s');

输出是:

2016-03-14 12:00:00

我试过更改时区,设置时区,将其关闭。输出永远不会改变。是什么赋予了?我希望输出读取2016-03-14 00:00:00。

I have tried to change timezones, set the timezone, leave it off. The output never changes. What gives? I want the output to read "2016-03-14 00:00:00".

推荐答案

您需要使用 H ,因为它是24小时的时间,而 h 是12小时的时间。 12:00:00是凌晨12点或00:00:00:

You need to use H as it is for 24 hour time and h is 12 hour time. 12:00:00 is 12am or 00:00:00:

$begin = new DateTime('2016-03-14 00:00:00');
echo $begin->format('Y-m-d H:i:s');

这篇关于new DateTime('2016-04-01 00:00:00')返回'04-04-01 12:00:00的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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