我正在编写php/javascript代码,在下面以法语返回月份名称,但它与我们使用的法语单词不匹配。
<script>
document.getElementById('title_fr').value = "<?php setlocale(LC_TIME, "frc"); echo strftime("%d %b %Y", strtotime( $this_date )); ?>";
</script>
上面的脚本以法语返回月份名称,这与我们的一组法语月份名称不匹配。
mars
avr.
mai
juin
juil.
août
sept.
oct.
nov.
déc.
以下是我们所采用的法语月份名称:
janvier
février
mars
avril
mai
juin
juillet
août
septembre
octobre
novembre
décembre
问题陈述:
我想知道我需要在上面的脚本中做什么修改,以便让它以法语命名,这是我所遵循的。
我相信我需要创建一个数组,如下图所示,用法语表示月份名称。
const monthNamesFr = ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"];
发布于 2019-03-14 15:03:01
因为这似乎起了作用(来自注释部分)。不要在数组中硬编码日期,只需从strftime()
函数中请求整个月:
setlocale(LC_TIME, "frc"); echo strftime("%d %B %Y", strtotime( $this_date ));
发布于 2019-03-14 15:04:05
我建议在法国使用有效的语言环境,如fr_FR
。此外,使用%B
作为每个 documentation的完整月份名称。
$this_date = '2018-04-03 12:12:12';
setlocale(LC_TIME, "fr_FR");
echo strftime('%d %B %Y', strtotime($this_date)); // 03 avril 2019
不管系统的配置区域设置如何,这都是可行的。
https://stackoverflow.com/questions/55165232
复制相似问题