Moment Js Get Name Of The Day In Different Language
I am trying to get the name of the day in French using Moment.js moment('01-06-2018').locale('Fr').format('dddd') This returns 'Saturday' whereas I want to get the name of the day
Solution 1:
Please make sure you have imported fr
locale and do not use moment(String)
with non ISO 8601 inputs, use moment(String, String)
instead.
As locale docs says:
By default, Moment.js comes with English (United States) locale strings. If you need other locales, you can load them into Moment.js for later use.
In the browser, you can use both moment/locale/fr.js
(French localization) file or use moment-with-locales.js
file that includes each locale setting supported by moment, see moment docs for other environments.
Here a live sample:
console.log(moment("01-06-2018", 'MM-DD-YYYY').locale("fr").format("dddd"));
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment-with-locales.min.js"></script>
Solution 2:
You need to make sure the proper file is included.
moment("01-06-2018").lang("Fr").format("dddd");
var res = moment("01-06-2018", 'MM-DD-YYYY').locale("Fr").format("dddd");
console.log(res);
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment-with-locales.min.js"></script>
Post a Comment for "Moment Js Get Name Of The Day In Different Language"