I'm working with Moment.js for my first time. I tried to retrieve the date of the first day of the week, and in Europe this is normally Monday. Whatever I do, I get Sunday as result of the first day of the week.
I tried to set-up different languages (local or globally), but to no avail. I use the langs.min.js file from the moment.js github page. The language file of "en-gb" and "fr" has the line of code:
dow : 1, // Monday is the first day of the week.
So I would get the date of monday when I ask for the first day of the week right? I keep getting Sunday as output.
// Create moment object
var localLang = moment();
// Set language to french
localLang.lang('fr');
// Test language
localLang.lang(); // Output: fr
// Retrieve first day of the week and format it
var dow = localLang.startOf('week').format('dddd DD-MM-YYYY'); // Output: dimanche 14-04-2013
Dimanche is french for Sunday.. As you see, moment.js can use the language file succesfully but doesn't use the day of the week configuration
JSfiddle with moment.js and langs.js to test: JSFiddle
edit:
I can get the date of Monday instead of Sunday with day(1)
instead of startOf('week')
. But using day(0)
I still get Sunday as a result. Why isn't monday the first day of the week, as configured in the language files.
To add time, pass the key of what time you want to add, and the amount you want to add. moment(). add(7, 'days');
MomentJs recently announced that the library is now deprecated. This is a big deal for the javascript community who actively downloads moment almost 15 million times a week. With that I began a journey during a Hackathon to replace moment in a core library at my company.
MomentJS is a widely used time and date formatting and calculation library.
For anyone who come across this question lately, moment now support lang
method to set locale specific setting.
Setting first week to be Monday:
moment.lang('zh-cn', {
week : {
dow : 1 // Monday is the first day of the week
}
});
var date = moment().weekday(0); // date now is the first day of the week, (i.e., Monday)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With