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

Member

by denis , in category: Javascript , 3 months ago

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

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by giovanny.lueilwitz , 3 months 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.