Are there any Node.js modules that provide fuzzy date strings?

I think of lines like β€œone minute ago” or β€œ3 weeks ago,” something like this.

I could easily transfer the examples that I found in other languages, but there is no need to reinvent the wheel if this material already exists.

+6
source share
3 answers

Something you can try is date.js: http://www.datejs.com/

To make it node compatible at the very bottom of the script, add the line:

module.exports = Date;

Then you can demand it:

var date = require('./date');

Assuming date.js is in the same folder, otherwise change the required path.

Then a simple example code for testing:

console.log( date.today().next().thursday() )

+2
source

I wrote a library called moment , which does what DateJS does, only it does less, does not change Date.prototype and works both in the browser and in NodeJS.

 npm install moment 

Using:

 moment(1316369911638).fromNow() // "3 minutes ago" 

It supports i18n and customization, all lines are subject to change.

+4
source

I found that require(./date) (i.e. using datejs directly) and datejs from npm install datejs do not work as advertised, at least with node v0.4.9.

The datetime module seems to work for me:

 $ npm install datetime datetime@0.0.2 ./node_modules/datetime └── vows@0.5.8 $ node --version v0.4.9 $ node > var datetime = require('datetime') > now = new Date() Thu, 14 Jul 2011 05:50:06 GMT > # wait for a bit ... ... > datetime.formatAgo(now) '18 seconds ago' 
+1
source

Source: https://habr.com/ru/post/888773/


All Articles