Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has anyone used the excellent Date.js library inside node.js?

Has anyone created a commonjs wrapper for Date.js? I'd like to use the Date.js library inside node and don't want to import it as a bare file and eval it if I can help it.

like image 817
Nitin Avatar asked May 27 '11 03:05

Nitin


2 Answers

I wrote a date library similar to DateJS that doesn't modify the Date.prototype. You may want to use that instead if you're worried about modifying the native Date object.

It handles parsing, manipulation, and formatting, as well as timeago and i18n.

npm install moment

Documentation at http://momentjs.com/docs

like image 129
timrwood Avatar answered Sep 23 '22 04:09

timrwood


What do you mean by a 'commonjs wrapper'? This code worked fine for me:

require('./date');

console.log(Date.today().add(5).days());

Date is a global object, and when you do the require, date.js modifies the global object. It didn't seem to mess up the regular date stuff. I would personally want to refactor it, because modifying the global object seems a little scary to me.

like image 34
beatgammit Avatar answered Sep 24 '22 04:09

beatgammit