0

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

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

4

1 回答 1

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;
于 2013-06-20T06:58:21.920 回答