Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm thinking of strings like "one minute ago" or "3 weeks ago", that kind of thing.

I could easily port examples I've found in other languages but there's no need to reinvent the wheel if this stuff is already out there.

like image 404
alnorth29 Avatar asked May 22 '11 17:05

alnorth29


2 Answers

I wrote a library called moment that does what DateJS does, only it's smaller, doesn't modify Date.prototype, and works in both the browser and NodeJS.

npm install moment

Usage:

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

It supports i18n and customization as well, all strings are exposed for modification.

like image 60
timrwood Avatar answered Oct 29 '22 20:10

timrwood


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 require it:

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

Assuming date.js is in the same folder, otherwise modify the require path.

Then a simple code sample to test is:

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

like image 42
tbranyen Avatar answered Oct 29 '22 22:10

tbranyen