javascript 如何使用momentjs从日期中获取当天的名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27830335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 08:03:15  来源:igfitidea点击:

How to get name of the day from date with momentjs

javascriptmomentjs

提问by IanWatson

I am using momentjsand want to output the name of the day ie. "Wednesday" but the API only seems to offer a number.

我正在使用momentjs并想输出当天的名称,即。“星期三”,但 API 似乎只提供了一个数字。

Is there a way to do this without hard-coding it to a particular language?

有没有办法在不将其硬编码为特定语言的情况下做到这一点?

回答by James Donnelly

From the Format section of their documentation:

他们文档格式部分

Day of WeekddddSunday Monday ... Friday Saturday

本周日dddd星期日星期一......星期五星期六

moment().format('dddd');