3

WordPressのWebサイトに現在の日付と時刻を表示しようとしています。日付と時刻に、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 m/d/Y ?>

現在の日付を出力するための私のウェブサイトのコードに、しかしそれは機能しませんでした。私は何が欠けていますか?

4

2 に答える 2

5

私はあなたがしなければならないと思います

 <?php echo date_i18n( 'm/d/Y' ) ?>
于 2013-01-22T03:03:38.363 に答える
5

試してみてください:

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

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

WordPressにはcurrent_time()ブログの時間を返す機能がありますが、ブログの設定で別のタイムゾーンを選択した場合はサーバーの時間とは異なる場合があります...

于 2013-01-22T03:11:05.040 に答える