This question already has an answer here:
这个问题在这里已有答案:
- get UTC time in PHP 11 answers
以PHP 11答案获得UTC时间
We are storing user timezone into database and I am looking current date from UTC time zone. I have timezone data like +5.5, -7, +2.5. and want to get current time from Timezone.
我们将用户时区存储到数据库中,我正在查看UTC时区的当前日期。我有时区数据,如+5.5,-7,+ 2.5。并希望从时区获得当前时间。
How i can get current date from PHP or MYsql.
我如何从PHP或MYsql获取当前日期。
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;
#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;