将月份名称更改为法语

时间:2011-09-05 15:20:16

标签: php symfony-1.4

我有这段代码:

<?php 
  echo "'".$sgps_newsletter->getEmail()."' demande en ".date('d.M.Y', strtotime($sgps_newsletter->getCreatedAt())) 
?> 

但月份名称以英文显示。我该怎么做才能用法语展示它?我已将settings.yml默认文化更改为法语,但没有任何反应。

5 个答案:

答案 0 :(得分:15)

使用strftimehttp://php.net/manual/en/function.strftime.php

<?php
setlocale(LC_TIME, "fr_FR");
echo strftime(" in French %d.%M.%Y and");

(不确定%d。%M.%Y但你可以阅读文档)

答案 1 :(得分:14)

来自http://php.net/manual/en/function.date.php

  

要格式化其他语言的日期,您应该使用setlocale()和   strftime()函数而不是date()。

答案 2 :(得分:13)

我知道这已经过时了,但是对于那些仍然在寻找这个问题的人来说,你在法语上约会的答案会更完整:

//set locale
setlocale(LC_TIME, "fr_FR"); 

然后

//echo date/formatting based on your locale, in this case, for French
echo strftime("le %d %B, %Y", strtotime( $sgps_newsletter->getCreatedAt() ));
//without day of the week = le 18 septembre, 2013

OR

echo strftime("%A le %d %B, %Y", strtotime( $sgps_newsletter->getCreatedAt() ));
//with day of the week = mercredi le 18 septembre, 2013

OR

echo strftime("%d/%m/%Y", strtotime( $sgps_newsletter->getCreatedAt() ))
//numerical, separated by '/' = 18/9/2013

答案 3 :(得分:10)

# --------------------
# METHOD 1
# --------------------
# set locale first
setlocale (LC_TIME, 'fr_FR.utf8','fra'); 
// setlocale(LC_TIME, 'fr_FR.UTF8');
// setlocale(LC_TIME, 'fr_FR');
// setlocale(LC_TIME, 'fr');
// setlocale(LC_TIME, 'fra_fra');
# Examples using current time
echo strftime('%Y-%m-%d %H:%M:%S');  // 2015-03-02 17:58:50
echo strftime('%A %d %B %Y, %H:%M'); // lundi 02 mars 2015, 17:58
echo strftime('%d %B %Y');           // 02 mars 2015
echo strftime('%d/%m/%y');           // 02/03/15
# Example with given timestamp
$timestamp = time () ; // Any timestamp will do
echo strftime( "%d %B %Y", $timestamp ) ;  // 02 mars 2015

# --------------------
# METHOD 2 
# --------------------
# using arrays without setting the locale ( not recommanded )
$day = array("Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi"); 
$month = array("janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"); 
// Now
$date = explode('|', date("w|d|n|Y"));
// Given time
$timestamp = time () ;
$date = explode('|', date( "w|d|n|Y", $timestamp ));
echo $day[$date[0]] . ' ' . $date[1] . ' ' . $month[$date[2]-1] . ' ' . $date[3] ; // Lundi 02 mars 2015

答案 4 :(得分:1)

使用strftime