我有下面這段PHP的,通過我的wordpress的帖子循環:轉換日期格式
<?php
$items = 0;
$thiscat = get_category(2);
$cat_slug = $thiscat->slug;
$args = array(
'post_type' => 'Course',
'category_name' => $cat_slug,
'order' => 'ASC',
);
$loop = new WP_Query($args);
while ($loop->have_posts() AND $items < 3) {
$loop->the_post();
$category_course = get_the_category(2);
$cat_slug_course = $category_course[0]->slug;
$date_start = get_post_meta(get_the_ID(), 'date_start', true);
$place = get_post_meta(get_the_ID(), "place", true);
$date_start = date("D, M d, Y", $date_start);
if(strtotime($date_start) >= strtotime('today')) { ?>
<li>
<a href="<?php the_permalink(); ?>" class="date_fp"><?php echo $date_start; ?> - <?php echo $place; ?></a>
</li>
<?php $items++; }
}
if($items==0) { ?>
<li>
Ingen kommende kurser
</li>
<?php } ?>
它循環並顯示多達三個的開始日期的課程。不過,我希望$date_start
以丹麥語而不是英語輸出。
我試着用strftime更換日期,並試圖建立locale丹麥,但在某種程度上,更改日期格式時STRFTIME(%A,%d%B,%Y),我的循環只是輸出Ingen kommende kurser
(無未來課程)。這很奇怪,因爲在使用日期(並獲取英文輸出)時,會顯示課程日期。
$ DATE_START輸出以毫秒爲單位
一個解決方案,我試過的時間(例如1371081600137535
),但沒有奏效:
...
$place = get_post_meta(get_the_ID(), "place", true);
setlocale(LC_ALL, 'nl_NL');
$date_start = strftime("%a, %d %b, %Y", mktime($date_start));
if(strtotime($date_start) >= strtotime('today')) { ?>
...
您確定您的系統上安裝了所需的區域設置嗎? – nils