简体   繁体   中英

How to get GMT date in yyyy-mm-dd hh:mm:ss in PHP

I want to get the current date in yyyy-mm-dd hh:mm:ss format.

I have tried:

gmdate('yyyy-mm-dd hh:mm:ss \\G\\M\\T', time());

Its returning a wierd date:

13131313-1111-2323 0707:1111:3131

You don't have to repeat those format identifiers . For yyyy you just need to have Y , etc.

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

Manual

You can get that list of identifiers Here

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()); 

You had selected the time format wrong

<?php 
date_default_timezone_set('GMT');

echo date("Y-m-d,h:m:s");
?>

使用以下日期函数以MySQL格式获取当前时间/(如有要求提供的问题)

echo date("Y-m-d H:i:s", time());

You are repeating the 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());

gmdate() is doing exactly what you asked for.

Look at formats here: http://php.net/manual/en/function.gmdate.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM