0
PHP的地方时我使用这个功能来显示WP页面(通过function.php)的小时显示在WP内容页
function displaydate(){
return date('H:i');
}
但retourns我的服务器小时。
我希望它向我展示欧洲/巴黎时间。
感谢
PHP的地方时我使用这个功能来显示WP页面(通过function.php)的小时显示在WP内容页
function displaydate(){
return date('H:i');
}
但retourns我的服务器小时。
我希望它向我展示欧洲/巴黎时间。
感谢
使用date_default_timezone_set
设置时区:
function displaydate(){
date_default_timezone_set('Europe/Paris');
return date('H:i');
}
我建议使用DateTime
类来替代date()
一旦你开始添加复杂性,例如更改时区。
实施例:
function displaydate() {
$datetime = new DateTime;
$paris_tz = new DateTimeZone('Europe/Paris');
$datetime->setTimezone($paris_tz);
return $datetime->format('H:i');
}