FastDateFormat的替代方法,用于高效的日期解析? [英] Alternatives to FastDateFormat for efficient date parsing?

查看:1876
本文介绍了FastDateFormat的替代方法,用于高效的日期解析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过 SimpleDateFormat 了解性能和线程问题,我决定使用 FastDateFormat ,直到我意识到 FastDateFormat 仅用于格式化,无解析!

Well aware of performance and thread issues with SimpleDateFormat, I decided to go with FastDateFormat, until I realized that FastDateFormat is for formatting only, no parsing!

有没有替代 FastDateFormat ,可以开箱即用,比 SimpleDateFormat 更快。

Is there an alternative to FastDateFormat, that is ready to use out of the box and much faster than SimpleDateFormat?

我相信 FastDateFormat 是更快的一个,所以任何事情都会如此快。

I believe FastDateFormat is one of the faster ones, so anything that is about as fast would do.

只是好奇,任何想法为什么 FastDateFormat 不支持解析?不会严重限制其使用吗?

Just curious , any idea why FastDateFormat does not support parsing? Doesn't it seriously limit its use?

推荐答案

最好的猜测是保持FastDateFormat ...好吗?快速,限制它只显示。

At a best guess, it's to keep FastDateFormat... well... fast, by limiting it to display only.

Apache Commons DateUtils 有一个 parseDate 函数,但是在内部使用 SimpleDateFormat

Apache Commons DateUtils has a parseDate function, but that uses SimpleDateFormat internally.

另一种方法是使用 JodaTime 库。对于处理 DateFormat 日期日历对象。

An alternative is to use the JodaTime library. It's a complete replacement for dealing with DateFormat, Date, and Calendar objects.

JodaTime有一个 DateTimeFormatter ,可用于创建 DateTime 对象(JodaTime相当于Java的日期

JodaTime has a DateTimeFormatter that can be used to create DateTime objects (JodaTime's equivalent of Java's Date objects) from strings.

如何使用它的一个例子是这样的:

An example of how to use it is like this:

String strInputDateTime = "2010-12-27"; // An example, this would really come from outside
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd");
DateTime dt = fmt.parseDateTime(strInputDateTime);

我不知道这是否真的比 SimpleDateFormat

I don't know if this is really any faster than SimpleDateFormat, though.

这篇关于FastDateFormat的替代方法,用于高效的日期解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆