![](/img/trans.png)
[英]How to differentiate between a month, and the first day of a month in Moment.js
[英]get the name of the Day from first day of the month in Moment.js
我正在嘗試使用Moment.js在JS中建立日歷
我正在嘗試獲取每月第一天的名稱,例如
1.6.2018是:“星期五”
我嘗試過此操作,但第一個日期已成為月份()中第一天的對象,而我只是不知道如何從該對象中提取日期名稱
{
let date=;
let firstDate;
date=moment().format();
console.log(date);
firstDate=moment(date).startOf(`month`);
console.log(firstDate)
firstDate=moment(firstDate).date(1);
console.log(firstDate);
}
也許您對我有更好的解決方案?
如果您不想打擾一下,可以這樣做:
console.log("Default:", new Date(2018,5,1).toLocaleDateString(undefined, { weekday: 'long' }) ) console.log("English:", new Date(2018,5,1).toLocaleDateString("en-US", { weekday: 'long' }) ); console.log("Hebrew:", new Date(2018,5,1).toLocaleDateString("he-IL", { weekday: 'long' }) )
如何獲得當前月份第一天的名稱呢?
moment().startOf('month').format('dddd');
當然,這只是讓你當月的第一天,如果要更改月份,只需撥打.startOf('month').format('dddd')
上的任何其他日期/時刻,你希望一個月內。
無論如何,您正在尋找的是.format('dddd')
,它將返回時刻的名稱;)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.