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');
}