当前位置:Gxlcms > PHP教程 > php时区转换函数示例

php时区转换函数示例

时间:2021-07-01 10:21:17 帮助过:13人阅读

  1. /*

  2. * 时区转换
  3. */

  4. function toTimeZone($src, $from_tz = 'America/Denver', $to_tz = 'Asia/Shanghai', $fm = 'Y-m-d H:i:s') {

  5. $datetime = new DateTime($src, new DateTimeZone($from_tz));
  6. $datetime->setTimezone(new DateTimeZone($to_tz));
  7. return $datetime->format($fm);
  8. }

人气教程排行