Reputation: 1380
I am trying to convert any timezone to LONDON timezone. At this moment the daylight concept is not considered.
When my time is : 07-04-2016 03:00 PM expected in LONDON is : 07-04-2016 10:30 AM
In my case it is : 07-04-2016 09:30 AM
Here is my php code in CI Helper:
function convert_datetime_to_utc_timezone($date, $timezone) {
if ($date != '') {
$ci = & get_instance();
$dformat .= "Y-m-d H:i:s";
$zone = get_list_of_all_timezone();
$user_time_zone = $zone[$timezone];
$convert_date = new DateTime($date, new DateTimeZone($user_time_zone));
$convert_date->setTimeZone(new DateTimeZone('UTC'));
return $convert_date->format('Y-m-d H:i:s');
} else {
return '';
}
}
Note: $user_time_zone = 'Asia/Calcutta';
Upvotes: 0
Views: 176
Reputation: 41
If you want to convert your local time to London time, then please use 'Europe/London'. The general time zones like UTC, EST etc wouldn't consider day light saving time.
$your_date = date ( 'Y-m-d H:i:s', strtotime ( $your_date ) );
$newyork_time = new DateTime ( $your_date, new DateTimeZone ( 'America/New_York' ) );
$london_time = new DateTime ( $your_date, new DateTimeZone ( 'Europe/London' ) );
Upvotes: 3
Reputation: 14762
If you want London time, then set the timezone to 'Europe/London', not UTC.
$ php -a
Interactive mode enabled
php > $format = 'd-m-Y H:i A';
php > $input_timezone = 'Asia/Calcutta';
php > $input_datetime = '07-04-2016 03:00 PM';
php > $datetime = DateTime::createFromFormat($format, $input_datetime, new DateTimeZone($input_timezone));
php > $datetime->setTimeZone(new DateTimeZone('Europe/London'));
php > var_dump($datetime->format($format));
string(19) "07-04-2016 10:30 AM"
Upvotes: 0