

Discover more from Tech Stack Collection Share
Yunan Camellia japonica
Working with DateTime in JavaScript can be complicated. Fortunately, many utility libraries are available to help make it easier. This post will look at 8 of the most popular DateTime utility libraries.
1、Moment.js[1]
Moment.js is a lightweight JavaScript date library for parsing, manipulating, and formatting dates. It's easy to use, has a clean API, and works across different browsers.
2、Date-fns[2]
Date-fns is a modern JavaScript date utility library that provides an immutable, chainable API for manipulating dates. It supports over 150 locales, has a consistent syntax, and works across different browsers.
3、Luxon[3]
Luxon is a library for working with dates and times in JavaScript. It has a modern API, supports over 60 locales, and works across different browsers.
4、Day.js[4]
Day.js is a minimalist JavaScript date library that provides an immutable API for manipulating dates. It's lightweight, has a simple syntax, and works across different browsers.
5、js-joda[5]
js-joda is a DateTime library for JavaScript that provides an immutable API for manipulating dates. It supports over 30 locales, has a rich API, and works across different browsers.
Download Compares
The following three libraries are specially designed to solve one scenario.
6、pretty-ms[6]
Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`
7、suncalc[7]
A tiny JavaScript library for calculating sun/moon positions and phases.
8、timeago.js[8]
🕗 ⌛ timeago.js is a tiny(2.0 kb) library used to format date with `*** time ago` statement.
Testimonial
Working with DateTime in JavaScript can be complex, but you can make it easier with the right library. The 8 libraries discussed in this post are all great options for working with DateTime in JavaScript.
I preferred to use the Day.js in your front-end project. Here’s why:
Day.js is a minified version of Moment.js. It claims to have the same API and reduce its file size by 97%. That's right; Moment.js' full minified file is 67.9Kb, whereas Day.js' is only 2Kb. This includes support for internationalization, plugins, and more.
References
[1] moment: https://github.com/moment/moment
[2] date-fns: https://github.com/date-fns/date-fns
[3] luxon: https://github.com/moment/luxon
[4] dayjs: https://github.com/iamkun/dayjs
[5] js-joda: https://github.com/js-joda/js-joda
[6] pretty-ms: https://github.com/sindresorhus/pretty-ms
[7] suncalc: https://github.com/mourner/suncalc
[8] timeago.js: https://github.com/hustcc/timeago.js
[9] tech-stack.tools: https://tech-stack.tools/
- END -