It also comes with a great many features, but in contrast to libraries like Lodash, it doesn’t allow you to cherry-pick the ones you need. This significantly increases your bundle size and you need to resort to plugins to get it back down. For example, if you use it with webpack, just an innocent require('moment') is enough ensure that all of the locales come along for the ride. Internationalization with Moment.js by SitePoint ( CodePen.Īlthough Moment.js is an excellent time and date library, it is also something of a behemoth. format ( 'dddd Do MMMM, YYYY' ) ) // jeudi 9e janvier, 2020 fromNow ( ) ) // il y a une heure console. Weekdays : 'dimanche_lundi_mardi_mercredi_jeudi_vendredi_samedi'. Months : 'janvier_février_mars_avril_mai_juin_juillet_août_septembre_octobre_novembre_décembre'. The following abridged example, taken from the Moment.js docs, shows how support can be added for French. If you want to support any other language, then assign the key values of that particular language to moment.locale. By default, it supports the English language. It allows you to assign a global language or set the language for a particular moment object. format ( 'dddd Do MMMM, YYYY' ) ) // Thursday 16th January, 2020 const today = moment ( ) const nextWeek = today. If you want a human-readable date, you’ll need to format it accordingly. Note that each of the above examples will return the moment object. subtract ( 7, 'years' ) // subtracts 7 years to current date subtract ( 7, 'months' ) // subtracts 7 months to current date moment ( ). subtract ( 7, 'days' ) // subtracts 7 days to current date moment ( ). Similarly, the subtract() method is shown below. add ( 7, 'years' ) // adds 7 years to current date add ( 7, 'months' ) // adds 7 months to current date moment ( ). add ( 7, 'days' ) // adds 7 days to current date moment ( ). The following example shows how seven days, months, or weeks are added to the current date. This is achieved via the add() and subtract() methods. For example, you can add or subtract days, months, years, etc. There are a number of options for manipulating the moment object. You can read more about these and other available flags on the project’s homepage. nullInput – Set when the entered date is null.empty – Set when the entered date contains nothing parsable.invalidMonth – Set when the month is invalid, like Jannnuaarry. An example would be the 13th month or 32nd day.
0 Comments
Leave a Reply. |