首页 > 解决方案 > 如何在 php 中使用 setlocale 函数获取法语月份名称?

问题描述

我正在研究一个 php 代码 $formated_date_new = date('M d, Y',strtotime($this_date)); ,它给了我英文月份的名称。

<script>
       document.getElementById('title_en').value = "<?php echo $formated_date_new ?>";
</script>

上面的脚本以以下格式返回日期(月份名称为英文):

Mar 13, 2019 

为了获得法语月份的名称,我需要集成以下代码,但我不知道该怎么做。

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


我想要的 o/p 是:

13 mars 2019

标签: phpdatesetlocale

解决方案


使用 strftime 代替日期:

setlocale( LC_TIME, "fr_FR" );
$formated_date_new = strftime( "%d %b %Y", strtotime( $this_date ) );

strftime 参考:

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


推荐阅读