2017-04-11 65 views
0

我試圖在duth中取得我的日期。我將日期分成單獨的月份,日期和年份變量,並將月份數字更改爲文本,但現在我需要進入荷蘭語而不是英語。我發現一些關於它的信息,比如setlocale(LC_ALL, 'nl_NL'),但是我不能讓它工作。在荷蘭取得月份名稱

<?php 

     include_once("db/db.php"); 
     $statement = $db_con->prepare("select * from news_article where id > :id"); 
     $statement->execute(array(':id' => 0)); 
     $list = $statement->fetchAll(PDO::FETCH_ASSOC); 
    ?>  
<?php 
    foreach($list as $col) 
    { 
     // splitting into seperate month day year 
     $orderdate = explode('-', $col['datum']); 
     $year = $orderdate[0]; 
     $month = $orderdate[1]; 
     $day = $orderdate[2]; 

     $dateObj = DateTime::createFromFormat('!m', $month); 
     $monthName = 
     $dateObj->format('F'); 


     ?> 
//this needs to output in dutch 
<p class="month"><?php echo $monthName ?></p> 
+0

看看http://stackoverflow.com/questions/13845554/php-date-get-name-of-the-months-in-local-language –

+0

DateTime :: format ()不知道區域設置(http://php.net/manual/en/datetime.format.php#refsect1-datetime.format-notes),請使用strftime()代替 –

回答

0
<?php 
$f = date('F'); 
    function dutch_format($value) { 

     $months = array(
      "January" => "januari", 
      "February" => "februari", 
      "March" => "maart", 
      "April"  => "april", 
      "May"  => "mei", 
      "June"  => "juni", 
      "July"  => "Juli", 
      "August" => "augustus", 
      "September" => "september", 
      "October" => "oktober", 
      "November" => "november", 
      "December" => "december" 
     ); 

     return $months[$value]; 
    } 
    echo $f; 
    echo "<br/>"; 
    echo dutch_format($f); 
?> 

它將返回DUTCH格式。指導我,如果我做了任何錯誤

+0

請考慮使用'strftime'和區域設置那。如果您必須使用50種語言來維護系統,那麼您的解決方案可能會非常不方便。 –