是否有任何 Node.js 模块提供模糊日期字符串?
我正在考虑诸如“一分钟前”或“三周前”之类的字符串。
我可以轻松地移植我在其他语言中找到的示例,但如果这些东西已经存在,则无需重新发明轮子。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我编写了一个名为 moment 的库,它可以完成 DateJS 的功能,只是它更小,不会修改
Date.prototype
,并且可以在浏览器和 NodeJS 中工作。用法:
它也支持 i18n 和自定义,所有字符串都公开以供修改。
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.Usage:
It supports i18n and customization as well, all strings are exposed for modification.
您可以尝试的是 date.js: http://www.datejs.com/
使其与节点兼容在脚本的最底部添加以下行:
module.exports = Date;
然后你可以要求它:
var date = require('./date');
假设date.js 位于同一文件夹中,否则修改 require 路径。
然后,要测试的简单代码示例是:
console.log( date.today().next().thursday() )
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() )
我发现
require(./date)
(即直接使用 datejs)和npm install datejs
中的 datejs 并不像宣传的那样工作,至少在 Node v0 中是这样。 4.9.datetime
模块似乎对我有用:I've found that
require(./date)
(i.e. using datejs directly) and datejs fromnpm install datejs
don't work as advertised, at least with node v0.4.9.The
datetime
module seems to work for me though: