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

前端 未结 6 1525
旧时难觅i
旧时难觅i 2020-12-16 10:08

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 retur

相关标签:
6条回答
  • 2020-12-16 10:46

    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());
    
    0 讨论(0)
  • 2020-12-16 10:50

    gmdate() is doing exactly what you asked for.

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

    0 讨论(0)
  • 2020-12-16 11:08

    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()); 
    
    0 讨论(0)
  • 2020-12-16 11:09

    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

    0 讨论(0)
  • 2020-12-16 11:09

    Use below date function to get current time in MySQL format/(As requested on question also)

    echo date("Y-m-d H:i:s", time());
    
    0 讨论(0)
  • 2020-12-16 11:12

    You had selected the time format wrong

    <?php 
    date_default_timezone_set('GMT');
    
    echo date("Y-m-d,h:m:s");
    ?>
    
    0 讨论(0)
提交回复
热议问题