I have a varaiable which gets the server time;
$date =date("Y-m-d H:i:s");
suppose the server is in the USA then it the timezone of this date will be the timezone of USA.
And i want to convert this timezone to Asia/Karachi timezone.
Any Idea about this???
How to convert datetime to another datetimezone in php???
Moderator: General Moderators
-
jankidudel
- Forum Commoner
- Posts: 91
- Joined: Sat Oct 16, 2010 4:30 pm
- Location: Lithuania, Vilnius
Re: How to convert datetime to another datetimezone in php??
Maybe manually count the difference in the seconds between 2 timezones:
$your_timezone = time();
$difference = hourdifference * minutedifference * 60;
$second_timezone = $your_timezone (+/-) $difference;
, then in the date function as optional argument(timestamp) insert $second_timezone, http://lt.php.net/manual/en/function.date.php
$your_timezone = time();
$difference = hourdifference * minutedifference * 60;
$second_timezone = $your_timezone (+/-) $difference;
, then in the date function as optional argument(timestamp) insert $second_timezone, http://lt.php.net/manual/en/function.date.php
Re: How to convert datetime to another datetimezone in php??
http://us2.php.net/datetime :
Code: Select all
$dt = new DateTime();
echo $dt->format('Y-m-d H:i:s'); // in your us tz
$dt->setTimeZone(new DateTimeZone('Asia/Karachi'));
echo $dt->format('Y-m-d H:i:s'); // Karachi tzRe: How to convert datetime to another datetimezone in php??
Thank you Weirdan. Thank you very much.