Timezone conversion in php

后端 未结 9 1693
我寻月下人不归
我寻月下人不归 2020-11-22 04:19

Can anyone suggest an easy method to convert date and time to different timezones in php?

9条回答
  •  心在旅途
    2020-11-22 04:29

    An even simpler method looks like this:

    date_default_timezone_set('Europe/London'); // your user's timezone
    $my_datetime='2013-10-23 15:47:10';
    echo date('Y-m-d H:i:s',strtotime("$my_datetime UTC"));
    

    As described in the PHP manual, strtotime() accepts a timezone too, you just have to append it to your datetime.

    I recommend you to store all your datetimes in UTC because that way you won't have problems with the daylight savings.

提交回复
热议问题