用于格式化和解析日期和数字的 JavaScript 库
我正在寻找一个可以解析和格式化日期值和数字的 JavaScript 库。它不应该太大或太复杂,只要 4 个方法就足够了:parseDate、formatDate、parseNumber、formatNumber
//dt is a JavaScript date object, str a string containing a date, formatoptions specifies the format
var dt = parseDate(str, formatoptions);
var str = formatDate(dt, formatoptions);
//same applies for parseNumber and formatNumber just replace dt with nr which represents a JavaScript number
我已经问过 Google 先生了,但是那里有太多的库和文章,很难找到好的东西。许多库可以格式化数字或日期,但无法解析它们。或者它们不稳定(相当无错误)。
有什么建议吗?
更新:
- 遗憾的是服务器端处理并不是真正的选择。我知道 PHP 或 ASP 中对日期和时间操作的支持要好得多,
- 我包含了一些示例代码,这些代码是我期望从解析和格式函数中得到的
更新 2:
我发现了一个非常好的用于格式化数字的库,它称为 jquery-numberformatter
I'm looking for a JavaScript library which can parse and format date values and numbers. It should not be too big or complicated just 4 methods would suffice for me: parseDate, formatDate, parseNumber, formatNumber
//dt is a JavaScript date object, str a string containing a date, formatoptions specifies the format
var dt = parseDate(str, formatoptions);
var str = formatDate(dt, formatoptions);
//same applies for parseNumber and formatNumber just replace dt with nr which represents a JavaScript number
I've already asked Mr. Google but there are sooo many libraries and articles out there that it is hard to find something good. Many libs can format a number or date but can't parse them. Or they are not stable (reasonably bug-free).
Any recommendations?
update:
- Sadly serverside processing is not really on option. I know support for date and time manipulation is much better in PHP or ASP
- I included some sample code what I would expect from the parse and format functions
update 2:
I found quite a good library for formatting numbers which is called jquery-numberformatter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我一直在使用 http://www.datejs.com 中的 date.js。主页中的解析器将使您了解其功能。
I have been using date.js from http://www.datejs.com. The parser in the home page will give you an idea of its capabilities.
这些天我会看看 MomentJs。有大量的文档和测试。
These days I would look at MomentJs. Theres plenty of documentation and tests.