瞬间JS用不同的语言获取当天的名字 [英] moment JS get name of the day in different language

查看:69
本文介绍了瞬间JS用不同的语言获取当天的名字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Moment.js用法语获得当天的名字

I am trying to get the name of the day in French using Moment.js

moment("01-06-2018").locale("Fr").format("dddd")

这将返回"Saturday",而我想用法语获取日期名称

This returns "Saturday" whereas I want to get the name of the day in French

推荐答案

请确保您已导入fr语言环境,并且不要使用 moment(String, String) 代替.

Please make sure you have imported fr locale and do not use moment(String) with non ISO 8601 inputs, use moment(String, String) instead.

语言环境文档表示:

默认情况下,Moment.js随附英语(美国)语言环境字符串.如果需要其他语言环境,可以将它们加载到Moment.js中以供以后使用.

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文件,请参见

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.

这里有一个现场样本:

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>

这篇关于瞬间JS用不同的语言获取当天的名字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆