首页 > 解决方案 > 如何在php中用法语硬编码月份名称?

问题描述

我正在研究下面的 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"];

标签: phpstrftimemonthcalendarsetlocale

解决方案


因为这似乎在起作用(来自评论部分)。无需将日期硬编码在数组中,只需从strftime()函数中请求整月:

 setlocale(LC_TIME, "frc"); echo strftime("%d %B %Y", strtotime( $this_date ));

推荐阅读