How do you change the timezone in PHP for an existing timestamp?

后端 未结 2 562
青春惊慌失措
青春惊慌失措 2020-12-16 05:22

The code for the date and time function:

function date_and_time($format,$timestamp) {

$date_and_time = date($format,$timestamp);
return $date_and_time;

}
<         


        
相关标签:
2条回答
  • 2020-12-16 05:42

    Not sure if this what you're looking for, but try DateTime

    date_default_timezone_set('Europe/London');
    
    $datetime = new DateTime();
    $datetime->setTimestamp($yourTimestamp);
    echo $datetime->getTimezone()->getName();
    echo $datetime->format(DATE_ATOM);
    
    $la_time = new DateTimeZone('America/Los_Angeles');
    $datetime->setTimezone($la_time);
    echo $datetime->getTimezone()->getName();
    echo $datetime->format(DATE_ATOM);
    
    0 讨论(0)
  • 2020-12-16 05:43

    You can use the this function to set default time zone:

    date_default_timezone_set('Europe/London');
    
    0 讨论(0)
提交回复
热议问题