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.
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.
The library also supports both Flow andTypeScript.
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.
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.
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.
Note that these libraries are mostly either old and unmaintained, or very young, so dive in with care.