我正在尝试使用 Moment.js 获取法语日期的名称
moment("01-06-2018").locale("Fr").format("dddd")
这会返回“Saturday
”,而我想获取法语的日期名称
最佳答案
请确保您已导入 fr
区域设置并且不要使用 moment(String)
对于非 ISO 8601 输入,请使用 moment(String, String)
相反。
如locale docs说:
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.
在浏览器中,您可以同时使用 moment/locale/fr.js
(法语本地化)文件或使用包含每个文件的 moment-with-locales.js
文件moment 支持的区域设置,参见 moment docs适用于其他环境。
这是一个实时示例:
console.log(moment("01-06-2018", 'MM-DD-YYYY').locale("fr").format("dddd"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment-with-locales.min.js"></script>
关于javascript - moment JS 获取不同语言的当天名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50853874/