当前日期来自UTC时区

时间:2013-06-20 06:39:56

标签: php mysql sql

我们将用户时区存储到数据库中,我正在查看UTC时区的当前日期。 我有时区数据,如+5.5,-7,+ 2.5。并希望从时区获得当前时间。

我如何从PHP或MYsql获取当前日期。

1 个答案:

答案 0 :(得分:0)

<?php 

//current time zone to UTC
$date = new DateTime($datetime, new DateTimeZone(date_default_timezone_get()));

//set the time zone as UTC
$date->setTimezone(new DateTimeZone('UTC'));

//convert local time to UTC time
$date=$date->format("Y-M-D");

echo $date;

//--------------------------------------------------------------------

//UTC to some other time zone format

$date = new DateTime($datetime, new DateTimeZone("UTC"));

//set the time zone as UTC
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));

//convert local time to UTC time
$date=$date->format("Y-M-D");

echo $date;