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.
How i can get current date from PHP or MYsql.
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.
How i can get current date from PHP or 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;