42

9 Javascript Time And Date Libraries For 2018

 5 years ago
source link: https://www.tuicool.com/articles/hit/VNr6z2j
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

9 Javascript Time And Date Libraries For 2018

9 Javascript time and date manipulation libraries to use in 2018, and a few extra goodies.

67NzY3m.jpg!web

Some day we might create a library for actual time travel. Until then, we’ll have to make do with libraries that manipulate date and time in our apps.

Wether you need to create a calendar, an appointment scheduling system or an interface to integrate different people at different time zones, manipulating time in Javascript is essential the most Javascript applications.

Here are 9 useful and actively maintained libraries to help you manipulate time. Individual modules from most of these libraries can be used with Bit , a platform that turns components and modules into building blocks which can be discovered, used, developed and synced from any project. Try it out.

1. Date-fns

VBreAru.png!web

Date-fns is a growingly popular (11K stars, over half a million weekly NPM installs) time manipulation library for Javascript, chosen by many developers to replace moment.js ( see comparison ). Date-fns provides over 130 functions to manipulate dates in the browser and Node.js. Date-fns is built using pure functions and keeps things immutable while not changing passed date instances. It works well with bundlers such as webpack, Browserify, or Rollup and also supports tree-shaking. It can also be combined with Bit to make every function individually available to install, use and even modify.

The library also supports both Flow andTypeScript.

2. Moment

aQzAbiu.png!web

Moment.js is a well-known, useful and somewhat heavy time manipulation library designed to work both in the browser and in Node.js. At nearly 40K stars, Moment helps you parse, validate, manipulate, and display dates in javascript. Note that the moment object itself is mutable, so different operations change the original moment object. Here’s a useful cheatsheet .

3. Luxon

r2ayE3n.png!web

Built by one of Moment’s maintainers, and at 6.5K stars, luxon is a a Javascript library for working with dates and times with a more comprehensive interface than the native types it wraps. Unlike moment, Luxon objects are immutable so making changes actually means creating a new instance with different properties. Here’s a quick guide to creating your first DateTime class with Luxon.

4. Day JS

Nb2EVjj.gif
Credit: http://nmotw.in/dayjs/

At nearly 12K stars day.js is a 2KB date library alternative to Moment.js with a similar API. This library also helps you parse, validate, manipulate, and display dates and times, and is also immutable and chainable. Instead of modifying the native Date.prototype , Day.js creates a wrapper for the Date object, called Dayjs object. All API operations that change the Dayjs object in some way will return a new instance of it.

5. Ms.js

vAFV7bY.png!web
rmYnMnF.png!web

Brought to us by Zeit, ms.js is a narrow yet surprisingly useful library that converts various time formats into milliseconds. It also works the other way around, converting milliseconds into human-readable time formats. ms works in both Node.js and the browser.

6. Timeago.js

FfaUrea.png!web

Timeago is a ~2KB library that performs a specific useful action: converting time formats to present how much time has passed since then. 0 dependencies, and the library also supports localization. Here’s a demo .

7. Instadate

At “only” 800 stars, Instadate is a small library with a handful of performance orianted features. Instadate is more of a wrapper around the native JavaScript Date than a full on date library. It can run thousands of time and date manipulations per second, and also works with ES5 and ES6. The library has a handful of dependancies, including lodash.difference .

8. JS-Joda

At “only” 900 stars, JS-Joda is an immutable date and time library for javascript with a domain-driven API based on the ISO8601 calendar. It’s uniqueness lies in the fact that it doesn’t wrap Javascript’s Date object. Instead, , js-joda is a standalone date and time implementation. The library has no external dependancies. Here’s a link to the quick-start guide .

9. Spacetime

I7b6rqy.png!web
qUzyqiN.png!web

Spacetime is a lightweight javascript timezone library which, given its size, performs some pretty complex calculations and manipulations for working with timezones even taking into account daylight savings, hemispheres, leap-years and more, all with an API similar to Moment and no external dependencies.

Honorable mentions

Note that these libraries are mostly either old and unmaintained , or very young, so dive in with care.

Check out Bit

Bit is a platform that help increase code reuse and reduce overhead. You can use it to cherry-pick components and modules from different projects, and make them available to use and develop from any other project- without any refactoring, configurations or overhead. Feel free to jump in and give it a try.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK