[英]get the name of the Day from first day of the month in Moment.js
I am trying to build a calendar in JS using Moment.js 我正在尝试使用Moment.js在JS中建立日历
I am trying to get the name of the first day of the month, or example , 我正在尝试获取每月第一天的名称,例如
1.6.2018 is:"Friday" 1.6.2018是:“星期五”
I tried this but first date is becoming an object of the first day in month (), and I just don't know how to extract from this object the name of the day 我尝试过此操作,但第一个日期已成为月份()中第一天的对象,而我只是不知道如何从该对象中提取日期名称
{
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);
}
maybe you have a better solution for me? 也许您对我有更好的解决方案?
If you do NOT want to bother with moment, you can just do this: 如果您不想打扰一下,可以这样做:
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' }) )
What about this to get the name of the first day of the current month: 如何获得当前月份第一天的名称呢?
moment().startOf('month').format('dddd');
Of course, this only gets you the first day for the current month, if you want to change the month, just call .startOf('month').format('dddd')
on any other date/moment within the month you want. 当然,这只是让你当月的第一天,如果要更改月份,只需拨打.startOf('month').format('dddd')
上的任何其他日期/时刻,你希望一个月内。
Anyway, what you are looking for is .format('dddd')
which will return the name of the day of a moment ;) 无论如何,您正在寻找的是.format('dddd')
,它将返回时刻的名称;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.