在荷兰取得月份名称

问题描述:

我试图在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()代替 –

<?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种语言来维护系统,那么您的解决方案可能会非常不方便。 –