WordPress-显示当前日期和;基于网站时区的时间

WordPress-显示当前日期和;基于网站时区的时间,wordpress,Wordpress,我试图在我的WordPress网站上显示当前日期和时间。我希望日期和时间能够反映WordPress管理区中设置的时区 我在options-general.php中找到了以下代码: <tr> <th scope="row"><?php _e('Date Format') ?></th> <td> <fieldset><legend class="screen-reader-text"><span>

我试图在我的WordPress网站上显示当前日期和时间。我希望日期和时间能够反映WordPress管理区中设置的时区

我在options-general.php中找到了以下代码:

<tr>
<th scope="row"><?php _e('Date Format') ?></th>
<td>
    <fieldset><legend class="screen-reader-text"><span><?php _e('Date Format') ?></span></legend>
<?php

    $date_formats = array_unique( apply_filters( 'date_formats', array(
        __('F j, Y'),
        'Y/m/d',
        'm/d/Y',
        'd/m/Y',
    ) ) );

    $custom = true;

    foreach ( $date_formats as $format ) {
        echo "\t<label title='" . esc_attr($format) . "'><input type='radio' name='date_format' value='" . esc_attr($format) . "'";
        if ( get_option('date_format') === $format ) { // checked() uses "==" rather than "==="
            echo " checked='checked'";
            $custom = false;
        }
        echo ' /> <span>' . date_i18n( $format ) . "</span></label><br />\n";
    }

    echo '  <label><input type="radio" name="date_format" id="date_format_custom_radio" value="\c\u\s\t\o\m"';
    checked( $custom );
    echo '/> ' . __('Custom:') . ' </label><input type="text" name="date_format_custom" value="' . esc_attr( get_option('date_format') ) . '" class="small-text" /> <span class="example"> ' . date_i18n( get_option('date_format') ) . "</span> <span class='spinner'></span>\n";

    echo "\t<p>" . __('<a href="http://codex.wordpress.org/Formatting_Date_and_Time">Documentation on date and time formatting</a>.') . "</p>\n";
?>
    </fieldset>
</td>
</tr>

我想你必须这样做

 <?php echo date_i18n( 'm/d/Y' ) ?>

试试:

$format = get_option('date_format') . ' ' . get_option('time_format');

print date_i18n($format, current_time('timestamp'));

WordPress有一个函数可以返回博客时间,如果您在博客设置中选择了不同的时区,那么博客时间可能与服务器时间不同。

这是更好的答案。
$format = get_option('date_format') . ' ' . get_option('time_format');

print date_i18n($format, current_time('timestamp'));