Moment.JS

The native JavaScript Date object is not fun to work with. Moment.JS is fun to work with.

What is Moment.JS

Moment give you a sane way to interact with dates in JavaScript.

Moment.JS supports JavaScript date objects, unix time, date strings, and UTC among others.

How can I display them?

Lots of ways, it is really up to you.

Relative

My personal favorite is relative time. Relative time means it would display ‘3 minutes ago’ , ‘1 year ago’, that sort of thing.

Any way you want

Moment gives you the power to easily display in any format or order you want. DD MM YYYY. YYYY DD MM. Whatever you decide.

Yup, of course you can.

Query

You can find out if two dates are equal or the order in which they occur. You can also determine is a date occurred in daylight savings time or a leap year, handy.

Manipulate

Moment.JS’ manipulate features let you add and subtract time. As well as set maximum and minimum date/times for date objects.

Should I use it?

Yes, yes you should. If you want to display relative time, or display and manipulate dates from an API moment.js will make your life easier. You may think that its only a few lines of code for relative time, but there are cases you are not considering and tests you will forget to write.

Author

Casey Garland


Originally published at www.parsed.io.

Copyright © 2020.