English 中文(简体)
有人在node.js中使用过优秀的Date.js库吗?
原标题: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.

最佳回答

你说的commonjs包装器是什么意思?这个代码对我来说很好:

require( ./date );

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

Date是一个全局对象,当您需要时,Date.js会修改全局对象。它似乎并没有把常规约会的事情搞砸。我个人想重构它,因为修改全局对象对我来说有点可怕。

问题回答

我写了一个类似于DateJS的日期库,它不修改<code>date.protype</code>。如果你担心修改原生date对象,你可能需要使用它。

它处理解析、操作和格式化,以及timeago和i18n。

npm install moment

文档位于http://momentjs.com/docs

我正在使用Date.js,并让它增强内置的Date对象,它运行良好。

事实证明,将本机Date对象扩展为新对象并不是那么容易(请参阅如何扩展Javascript Date对象?)。

使用npm:

<code>$sudo npm install-g datejs</code>

datejs@0.0.2/usr/lib/node_modules/datejs

└── vows@0.5.9





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签