Reputation: 11679
I am working on a php/javascript code below which returns month names in French but it doesn't match the french words which we are using.
<script>
document.getElementById('title_fr').value = "<?php setlocale(LC_TIME, "frc"); echo strftime("%d %b %Y", strtotime( $this_date )); ?>";
</script>
The above script returns the month names in french which is not matching our set of month names in french.
mars
avr.
mai
juin
juil.
août
sept.
oct.
nov.
déc.
Following are the set of month names in French which we follow:
janvier
février
mars
avril
mai
juin
juillet
août
septembre
octobre
novembre
décembre
Problem Statement:
I am wondering what changes I need to make in the script above so that it returs month name in french which I am following.
I believe I need to create an array as shown below with the month names in french.
const monthNamesFr = ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"];
Upvotes: 2
Views: 1096
Reputation: 1235
I'd suggest using a valid locale such as fr_FR
for french language in France. Additionally, use %B
for the full month name per the strftime()
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
This works regardless of the system's configured locale.
Upvotes: 1
Reputation: 50034
Since this seems to be doing the trick (from the comments section). Instead of hardcoding your dates in an array, just request the full month from the strftime()
function:
setlocale(LC_TIME, "frc"); echo strftime("%d %B %Y", strtotime( $this_date ));
Upvotes: 1