在Java中解析日期的通用方式 [英] Generic way to parse dates in Java
本文介绍了在Java中解析日期的通用方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
标准API库中没有什么。 Natty 是一个图书馆,尝试这个,但你应该意识到,这只能是一个尽力而为的事情,事情像2012/2/1一样简单的模糊:没有关于格式的信息,不可能决定是二月一号还是一月二号。
What is the best way to parse dates in Java ? Is there any built in way to parse strings such as "18 Jul 2011" , "Jul 18, 2011", "18-07-2011", "2011-07-18" without knowing the format beforehand?
解决方案
There's nothing like that in the standard API library. Natty is a library that attempts this, but you should be aware that this can only ever be a "best effort" affair, as things like 2/1/2012 are simply ambiguous: without metainformation about the format, it's impossible to decide whether it's Feburary 1st or January 2nd.
这篇关于在Java中解析日期的通用方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文