Wordpress在functions.php上获取当前时间错误

时间:2014-10-10 22:17:39

标签: wordpress

我想获得wordpress的当前时间,但是我遇到了错误,如何解决?有没有另一种方法来获取wordpress的当前时间?我希望wordpress使用格式(+ GMT)和用户选择的时间,而不是服务器时间。

这是我的代码

<?php

require_once( '/wp-includes/functions.php' ); 
$format = get_option('date_format') . ' ' . get_option('time_format');
print date_i18n($format, current_time('timestamp'));

?>

这些是错误

Notice: Use of undefined constant ABSPATH - assumed 'ABSPATH' in C:\xampp1\htdocs\wp\wp-includes\functions.php on line 8

Notice: Use of undefined constant WPINC - assumed 'WPINC' in C:\xampp1\htdocs\wp\wp-includes\functions.php on line 8

Warning: require(ABSPATHWPINC/option.php): failed to open stream: No such file or directory in C:\xampp1\htdocs\wp\wp-includes\functions.php on line 8

Fatal error: require(): Failed opening required 'ABSPATHWPINC/option.php' (include_path='.;C:\xampp1\php\PEAR') in C:\xampp1\htdocs\wp\wp-includes\functions.php on line 8

1 个答案:

答案 0 :(得分:1)

您不需要包含require_once( '/wp-includes/functions.php' );。直接使用它将返回GMT时间的函数如下

<?php echo current_time( 'mysql', 1 ); ?>

有关详情,请参阅此链接http://codex.wordpress.org/Function_Reference/current_time