Page 1 of 1
How to convert datetime to another datetimezone in php???
Posted: Sat Jan 08, 2011 5:53 am
by hmdnawaz
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???
Re: How to convert datetime to another datetimezone in php??
Posted: Sat Jan 08, 2011 7:04 pm
by jankidudel
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
Re: How to convert datetime to another datetimezone in php??
Posted: Sun Jan 09, 2011 10:30 am
by Weirdan
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 tz
Re: How to convert datetime to another datetimezone in php??
Posted: Sun Jan 09, 2011 10:51 pm
by hmdnawaz
Thank you Weirdan. Thank you very much.