如何在 yyyy-mm-dd hh:mm:ss 中在 PHP 中获取 GMT 日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20159655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get GMT date in yyyy-mm-dd hh:mm:ss in PHP
提问by clu3Less
I want to get the current date in yyyy-mm-dd hh:mm:ss format.
我想以 yyyy-mm-dd hh:mm:ss 格式获取当前日期。
I have tried:
我试过了:
gmdate('yyyy-mm-dd hh:mm:ss \G\M\T', time());
gmdate('yyyy-mm-dd hh:mm:ss \G\M\T', time());
Its returning a wierd date:
它返回一个奇怪的日期:
13131313-1111-2323 0707:1111:3131
13131313-1111-2323 0707:1111:3131
回答by Hanky Panky
You don't have to repeat those format identifiers . For yyyyyou just need to have Y, etc.
您不必重复这些格式标识符。因为yyyy你只需要拥有Y,等等。
gmdate('Y-m-d h:i:s \G\M\T', time());
In fact you don't even need to give it a default time if you want current time
事实上,如果你想要当前时间,你甚至不需要给它一个默认时间
gmdate('Y-m-d h:i:s \G\M\T'); // This is fine for your purpose
You can get that list of identifiers Here
您可以在此处获取标识符列表
回答by vijaykumar
Try this
尝试这个
Check this How do i get the gmt time in php
date_default_timezone_set("UTC");
echo date("Y-m-d H:i:s", time());
回答by Ivin Polo Sony
You had selected the time format wrong
您选择了错误的时间格式
<?php
date_default_timezone_set('GMT');
echo date("Y-m-d,h:m:s");
?>
回答by Shiv Singh
Use below date function to get current time in MySQL format/(As requested on question also)
使用下面的日期函数以 MySQL 格式获取当前时间/(也按问题要求)
echo date("Y-m-d H:i:s", time());
回答by Kacer
gmdate()is doing exactly what you asked for.
gmdate()正在做你所要求的。
Look at formats here: http://php.net/manual/en/function.gmdate.php
回答by Tarun
You are repeating the y,m,d.
你在重复y,m,d.
Instead of
代替
gmdate('yyyy-mm-dd hh:mm:ss \G\M\T', time());
You should use it like
你应该像这样使用它
gmdate('Y-m-d h:m:s \G\M\T', time());

