<?php
/**
* 获取不同时区的时间字符串
* @param string $format 字符串格式
* @param string $timeZone 时区
* @return string
*/
function ex_date($format, $timeZone = null) {
if ($timeZone === null) {
$timeZone = date_default_timezone_get();
}
$dateTimeZone = new DateTimeZone($timeZone);
$dateTime = new DateTime();
$dateTime->setTimezone($dateTimeZone);
return $dateTime->format($format);
}
$format = 'Y-m-d H:i:s';
$gmtTime = ex_date($format, 'GMT');
$chinaTime = ex_date($format, 'Asia/Shanghai');
$koreaTime = ex_date($format, 'Asia/Seoul');
$newYorkTime = ex_date($format, 'America/New_York');
$londonTime = ex_date($format, 'Europe/London');
$output =<<<EOT
当前世界各地时间
格林威治(GMT):$gmtTime
中国:$chinaTime
韩国:$koreaTime
纽约:$newYorkTime
伦敦:$londonTime
EOT;
echo nl2br($output);
exit();
--------------------------------------------------
当前世界各地时间
格林威治(GMT):2019-02-24 15:09:11
中国:2019-02-24 23:09:11
韩国:2019-02-25 00:09:11
纽约:2019-02-24 10:09:11
伦敦:2019-02-24 15:09:11