Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert date to gmt - php

Tags:

php

I am having a strange problem, maybe you can help:

I'm trying to convert a date to GMT time, and this is what I'm doing:

$date = '2010-05-27 23:02:01';
$gmt_date = gmdate('Y-m-d H:i:s', $date );

but the yield of $gmt_date is this: 1970-01-01 00:33:31

What am I doing wrong?

like image 378
Hudson Atwell Avatar asked Dec 02 '22 05:12

Hudson Atwell


1 Answers

gmdate expects the second parameter to be an integer (the number of seconds from the unix epoch)

Try this:

$date = '2010-05-27 23:02:01'; 
$gmt_date = gmdate('Y-m-d H:i:s', strtotime($date) );
like image 66
Mitch Dempsey Avatar answered Dec 04 '22 12:12

Mitch Dempsey