Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

date

php

gmt

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

like image 969
clu3Less Avatar asked Nov 23 '13 07:11

clu3Less


4 Answers

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

like image 68
Hanky Panky Avatar answered Oct 13 '22 20:10

Hanky Panky


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()); 
like image 29
vijaykumar Avatar answered Oct 13 '22 20:10

vijaykumar


You had selected the time format wrong

<?php 
date_default_timezone_set('GMT');

echo date("Y-m-d,h:m:s");
?>
like image 32
Ivin Polo Sony Avatar answered Oct 13 '22 21:10

Ivin Polo Sony


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());
like image 21
Shiv Singh Avatar answered Oct 13 '22 20:10

Shiv Singh