Convert date to gmt - php

I have a strange problem, maybe you can help:

I am trying to convert the date to GMT, and this is what I am doing:

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

but the output $gmt_dateis this: 1970-01-01 00:33:31

What am I doing wrong?

+3
source share
2 answers

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

Try the following:

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

You need to convert the date $ date to a timestamp. You can do this using the strtotime () function. Depending on the time zones, you can set the php time zone or add the time zone to the $ date line before calling the strtotime function.

$gmdate_str = gmdate('Y-m-d H:i:s', strtotime($date));
+4
source

Source: https://habr.com/ru/post/1744644/


All Articles