WordPress - 显示当前日期 &基于网站时区的时间 [英] WordPress - Display Current Date & Time Based on Website Timezone
本文介绍了WordPress - 显示当前日期 &基于网站时区的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在我的 WordPress 网站上显示当前日期和时间.我希望日期和时间反映在 WordPress 管理区域中设置的时区.
I'm trying to display the current date and time on my WordPress website. I want the date and time to reflect the Timezone that has been set in the WordPress admin area.
我在 options-general.php 中找到了这段代码:
I found this code in 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 m/d/Y ?>
到我的网站代码输出当前日期,但没有用.我错过了什么?
To my website code to output the current date but it didn't work. What am I missing?
推荐答案
我认为你必须这样做
<?php echo date_i18n( 'm/d/Y' ) ?>
这篇关于WordPress - 显示当前日期 &基于网站时区的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文