很清楚SimpleDateFormat的性能和线程问题,我决定使用FastDateFormat,直到我意识到FastDateFormat只用于格式化,而不是解析!
是否有比SimpleDateFormat更快、开箱即用的FastDateFormat替代方案
我相信FastDateFormat是最快的之一,所以任何快的东西都可以。
好奇的是,你知道为什么FastDateFormat不支持解析吗?它不是严重限制了它的使用吗?
发布于 2010-12-28 04:51:50
最好的猜测是为了让FastDateFormat..。好吧..。快速,通过将其限制为仅显示。
Apache Commons DateUtils有一个parseDate函数,但它在内部使用SimpleDateFormat。
另一种方法是使用JodaTime库。它是处理DateFormat、Date和Calendar对象的完全替代。
JodaTime有一个DateTimeFormatter,可用于从字符串创建DateTime对象(JodaTime相当于Java的Date对象)。
如何使用它的示例如下所示:
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快。
发布于 2014-04-08 19:02:52
请注意,从commons-lang3.2开始,FastDateFormat支持解析和打印。
请参阅:http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/time/FastDateFormat.html
发布于 2011-05-13 02:44:20
在安卓系统中发现了一些有趣的东西:http://andmob.wikidot.com/faq-simpletimeformat
当您第一次尝试解析(或者可能是格式化)日期时,
SimpleDateFormat将加载您所在地区的所有时区数据。这将需要2-3秒。希望这个问题能在未来的Android版本中得到解决。
在此期间,考虑在您需要SimpleDateFormat之前,在您的流程中使用AsyncTask来“预热”它。只需解析AsyncTask doInBackground()中的某个日期,使其在不会对用户造成太大影响的情况下加载时区。在您的进程中初始化后,SimpleDateFormat将快速运行,直到您的进程终止。
https://stackoverflow.com/questions/4541636
复制相似问题