我们将用户时区存储到数据库中,我正在查看 UTC 时区的当前日期。我有 +5.5、-7、+2.5 等时区数据。并想从时区获取当前时间。
我如何从 PHP 或 MYsql 获取当前日期。
<?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;