Today in this tutorial I will let you know how to convert date and time from one timezone to another timezone in PHP. Following is a simple method with simple example of timezone conversion in PHP.
You can use the DateTime object and their function aliases like as below:
date_default_timezone_set('Europe/London'); $datetime = new DateTime('2016-04-17 08:35:23'); echo $datetime->format('Y-m-d H:i:s') . "\n"; $ca_time = new DateTimeZone('Asia/Calcutta'); $datetime->setTimezone($ca_time); echo $datetime->format('Y-m-d H:i:s');
Result is as follow:
2016-04-17 08:35:23 2016-04-17 13:05:23
DateTime is exists on PHP 5.2 and above. Hope this tutorial will help you.