Has anyone used the excellent Date.js library inside node.js?
Has anyone created a commonjs wrapper for Da开发者_如何学Gote.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.
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
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.
I'm using Date.js and having it augment the built-in Date object which is working fine.
Turns out extending the native Date object as a new object isn't that easy (see How to extend the Javascript Date object?).
Using npm:
$ sudo npm install -g datejs
datejs@0.0.2 /usr/lib/node_modules/datejs
└── vows@0.5.9
精彩评论