converting a time to a different timezone with php

前端 未结 6 2007
鱼传尺愫
鱼传尺愫 2020-12-11 17:38

$timeposted = \"7:10pm\";

This value is currently Canada time (quebec). I\'m trying to find a way to convert it to France\'s time. How can i do that ?

6条回答
  •  失恋的感觉
    2020-12-11 17:56

    Assuming that your PHP configuration is set to the Quebec time, you can convert it to France's timezone by doing the following:

    $date = new DateTime('7:10pm', new DateTimeZone('Europe/Paris'));
    echo $date->format('Y-m-d H:i:sP');
    

    Or, if your server is not set to the Quebec timezone you can:

    $date = new DateTime('7:10pm', new DateTimeZone('America/Montreal'));
    
    $date->setTimezone(new DateTimeZone('Europe/Paris'));
    
    echo $date->format('Y-m-d H:i:sP');
    

    which returns

    2013-06-14 01:10:00+02:00 
    

    You can read more about PHP and timezones here: http://www.php.net/manual/en/datetime.settimezone.php

提交回复
热议问题