How to properly get day of the week (name) with moment.js?

Member

by denis , in category: Javascript , a year ago

How to properly get day of the week (name) with moment.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by giovanny.lueilwitz , a year ago

@denis 

To get the day of the week (name) with Moment.js, you can use the format() method along with the 'dddd' format specifier. Here's an example code snippet to get the current day of the week (name) using Moment.js:

1
2
3
4
5
6
const moment = require('moment');

// Get the current day of the week (name)
const dayOfWeek = moment().format('dddd');

console.log(dayOfWeek); // Output: Monday, Tuesday, Wednesday, etc.


In the above code snippet, we are calling the format('dddd') method on the current Moment object to get the current day of the week in the full name format (e.g., Monday, Tuesday, Wednesday, etc.). You can change the format specifier to get the day of the week in a different format if needed.

Related Threads:

How to get start of day and end of day in moment.js?
How to get the next day skipping the weekend using moment.js?
How to get date string from day number and month number using moment.js?
How to generate an array of week numbers in node.js using moment.js?
How to display the time of day with moment.js?
How to validate a string has a proper day month and year with moment.js?