用于格式化和解析日期和数字的 JavaScript 库

发布于 2024-12-01 09:03:47 字数 837 浏览 0 评论 0原文

我正在寻找一个可以解析和格式化日期值和数字的 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素衣风尘叹 2024-12-08 09:03:47

我一直在使用 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.

空宴 2024-12-08 09:03:47

这些天我会看看 MomentJs。有大量的文档和测试。

These days I would look at MomentJs. Theres plenty of documentation and tests.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文