2016-10-10 127 views
0

我写了第一个wordpress插件,它查看服务器上的文件并返回时间戳。我的问题是,服务器的时间戳是上午8点,但返回值是13:00。如何在PHP中调整时间戳以匹配实时?以下是我使用的代码:在PHP中设置正确的时区日期函数

function wp_file_last_updated($atts){ 
$a = shortcode_atts (array(
    'url' => 'No File Specified' 
    ), $atts); 

$filename = $a['url']; 
if (file_exists($filename)) { 
return "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename)); 
} 
} 
add_shortcode('filedate', 'wp_file_last_updated'); 

?> 

回答

1

转到WordPress的一般设置和改变你的时区。 enter image description here

0
date_default_timezone_set("set supported time zone"); 
$date=date("Y-m-d H:i:s"); 

支持的时区是在http://php.net/manual/en/timezones.php

+0

谢谢!这解决了它..我很感激你花时间来帮忙。 – Craig