开发者

Convert date to gmt - php

开发者 https://www.devze.com 2022-12-30 03:34 出处:网络
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:

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?


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


You need to convert your $date into a timestamp. You can do this using the strtotime() function. Depending on timezones, you may want to set the php timezone or append a timezone to the $date string before calling the strtotime function.

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

精彩评论

暂无评论...
验证码 换一张
取 消