我正在编写下面的 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"];
最佳答案
因为这似乎有效(来自评论部分)。无需将日期硬编码到数组中,只需从 strftime()
函数请求完整月份即可:
setlocale(LC_TIME, "frc"); echo strftime("%d %B %Y", strtotime( $this_date ));
关于php - 如何在 php 中用法语对月份名称进行硬编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55165232/