2016-04-07 5 views
0

タイムゾーンをLONDONタイムゾーンに変換しようとしています。現時点では、昼光の概念は考慮されていません。php:CIの夏時間(ロンドン)問題

私の時間は次のとおりです。2016年7月4日午前3時00分PM LONDONに期待は次のとおりです。私の場合は2016年7月4日10:30

にあります:07-04-

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 ''; 
    } 
} 

注:ここでは9時30分AM

2016はCIヘルパーの私のPHPコードである $ user_time_zone = 'アジア/カルカッタ';

+1

ロンドンはGMT + 1ゾーンを持つ必要があります – Tomasz

+0

コードを変更する必要がありますか?お願いします! – VBMali

+0

コードベースは永続的なものなので、LONDONタイムゾーンが夏時間を持たない場合、またはその逆の場合にも機能します。 – VBMali

答えて

0

ロンドンタイムを使用する場合は、タイムゾーンをUTCではなく「Europe/London」に設定します。

$ 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" 
3

現地時間をロンドン時間に変換する場合は、「ヨーロッパ/ロンドン」を使用してください。 UTC、ESTなどの一般的なタイムゾーンでは、昼間の節約時間は考慮されません。

$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'));