php 将月份名称更改为法语

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7309960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:27:21  来源:igfitidea点击:

change month name to french

phpsymfony-1.4

提问by Eva Dias

I have this code:

我有这个代码:

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

but the month name is appering in english. What can I do to show it in french? I've change the settings.ymldefault culture to french, but nothing happens.

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

回答by Marek Sebera

Use strftime: http://php.net/manual/en/function.strftime.php

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

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

(not sure about that %d.%M.%Y but you can read documentation)

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

回答by Stefan H Singer

From http://php.net/manual/en/function.date.php:

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

To format dates in other languages, you should use the setlocale()and strftime()functions instead of date().

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

回答by acarito

I know this is old but for anyone still looking this up, a more complete answer for your date in French would be:

我知道这已经过时了,但对于仍在查找此内容的任何人来说,法语约会的更完整答案是:

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

Then

然后

//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

回答by Olivier

# --------------------
# 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

回答by steve