2014-04-01 3 views
0

번역 나는 내 워드 프레스 포스트를 통해 루프 PHP의 다음과 같은 부분이 있습니다날짜 형식

<?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을 영어 대신 덴마크어로 출력하고 싶습니다.

I 내 ​​루프는 아니오 (Ingen kommende kurser 출력 (% A, % d 개의 %의 ​​B, %의 Y)를 strftime로 일을 1,8- 덴마크어 locale을 설정했지만, 어떠한 방법으로, 날짜 형식을 변경할 때하면 STRFTIME하려고 미래 과정). 이것은 이상한 일입니다. 왜냐하면 날짜로 작업 할 때 (그리고 영어 출력을 얻을 때), 코스 날짜가 표시되기 때문입니다.

$의 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')) { ?> 
... 
+0

시스템에 원하는 로케일이 설치되어 있습니까? – nils

답변

1

당신은 더블 데이트 변환하기 : 1) 타임 스탬프 텍스트로를; 2) 타임 스탬프에 텍스트. 반면 당신은 어떤 변환도 필요하지 않습니다. get_post_meta으로 얻은 타임 스탬프를 if 문에 간단히 사용할 수 있습니다. setlocale은 서식 설정에만 영향을 주며 시간대에는 영향을주지 않습니다. 덴마크어 표준 시간대를 적용하려면 date_default_timezone_set으로 전화해야합니다.

이 시도 :

... 
    $date_start = get_post_meta(get_the_ID(), 'date_start', true); 
    $place = get_post_meta(get_the_ID(), "place", true); 
    date_default_timezone_set('Europe/Copenhagen'); 
    if($date_start >= strtotime('today')) { 
     ...       
     echo date("D, M d, Y", $date_start); 
     ...       
    } 
    ... 
0

날짜 값이 잘못 때문에 시간대 차이로 번역 될 가능성이있다.

// $date_start is already a timestamp so do not do conversion 
// $date_start = date("D, M d, Y", $date_start); 
if($date_start >= strtotime('today')) { ?> 
<li>        
    <a href="<?php the_permalink(); ?>" class="date_fp"><?php echo date("D, M d, Y", $date_start); ?> - <?php echo $place; ?></a> 
</li> 
<?php $items++; } 

이 코드는 계산을 위해 날짜를 변환 피 같은 것을하려고 노력하지만, 디스플레이를 위해 그렇게 할 것입니다.