6 个JavaScript日期处理库
1. Later.js
Later.js, a stadalone JavaScript library, offers an advanced usage for triggering recurring events and can easily replace both methods for many projects. Also, the library accepts cron expressions or user friendly schedules (like “every 10 seconds”). P.S. It works both in the browser and Nodejs.
2. Countdown.js
Countdown.js is a JavaScript library for calculating and displaying the timespan between two dates. The library calculates the value continuously considering “the time goes on” and keeps generating an accurate output. It can provide the time span in many formats like milliseconds, seconds, minutes, hours, days, weeks and even millennias. There are methods for displaying it as an English sentence like “3 years, 6 months, 21 days, 10 hours, and 32 minutes”. The countdown can be reset easily and there are callbacks both on startand end.
3. Moment.js
Moments.js is a feature-rich JavaScript library for working with dates (parsing, manipulating, and formatting them). It works both in the browser and server with NodeJS as all code is compatible with both of the environments. The library can easily convert any given date to many different formats, add/subtract dates, hours, etc. and has methods for displaying user-friendly date/times like “in 5 days” Moment.js is multilanguage and any new languages can be easily added by editing a language file.
4. Date.js
Datejs is an open-source JavaScript Date Library. With simple to use commands, Datejs provides many useful date functions like: last December, next Thursday, +10years, & many date format conversions. Date objects in JavaScript are generally problematic as they may require complicated calculations to run. Datejs is absolutely a life-saver in this area.
5. Cubism.js
Cubism.js is a plugin for D3.js, a JavaScript visualization library for HTML and SVG, to display time series in real-time. It requests the data incrementally by polling only the most recent values and reduces the load on the server. Charts are rendered incrementally as well by shifting charts one pixel each time to the left. Cubism is data-source agnostic. It has built-in support for Graphite and Cube, and can be readily extended to fetch data from other sources.
6. Xdate.js
XDate is another library similar to String.js but for parsing, formatting and manipulating dates. The library is standalone, only 2.9kb gzipped, has chaining support and brings very handy methods like: getting date values, adding-subtracting dates, calculating differences, and getting outputs in multiple formats. It also has a wide set of methods for working with UTC values.