<?php
function changeTimeZone($date_time, $format = 'Y-m-d H:i:s', $to = 'Europe/Rome', $from = 'Asia/Shanghai') {
    $datetime = new DateTime($date_time, new DateTimeZone($from));
    $datetime->setTimezone(new DateTimeZone($to));
    return $datetime->format($format);
}

$time = changeTimeZone('2018-12-19 00:00:00');
$t = changeTimeZone('2018-12-19 00:00:00', 'Y-m-d');
echo $time;
echo $t;

运行结果:

2018-12-18 17:00:00
2018-12-18 

其他PHP支持的时区编码请在以下页面查询:

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-26
  • 2021-12-29
  • 2021-09-28
  • 2021-10-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-12
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2021-07-10
  • 2021-11-14
相关资源
相似解决方案