Merbin Jo Merbin Jo - 6 months ago 36
PHP Question

How to convert Localtime to user seleted timezone in php

I want to convert the India time to user selected timezone in php. I used the following php code, but it showing some error " Uncaught exception 'Exception' with message 'DateTimeZone::__construct(): Unknown or bad timezone (+13:40)'".

My php code

$date = new DateTime('2016-10-22 01:39:53 +5:30');
$date->setTimezone(new DateTimeZone('+13:40'));
echo $date->format('Y-m-d H:i:s');

But this code is working perfectly in phpfiddle.

Working link here


That's likely a PHP version problem. From my tests it seems that PHP versions before 5.5.10 do not support the +nn:nn timezone format:


Try replacing it with a named timezone from the List of Supported Timezones or upgrade your PHP version.