Java的智能日期/时间解析器 [英] Intelligent date / time parser for Java
本文介绍了Java的智能日期/时间解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
日历cal = DateTimeParser.parse(01/06/10 14:55) ;
cal = DateTimeParser.parse(2009年1月1日); //假设00:00时间
cal = DateTimeParser.parse(1.2.2010);
cal = DateTimeParser.parse(kygyutrtf); // throws exception
更新:
//我告诉解析器:如果不确定,假设美国日期格式
cal = DateTimeParser.parse(01/02/03 ,新的Locale(en-us));
解决方案
JodaTime 非常适合操纵日期对象(例如date.plusDays(10))
.. 。但是 JChronic 是您想要的自然语言日期解析,例如
Chronic.parse(now)
Chronic.parse(tomorrow 15:00)
Chronic.parse(14/2/2001)
Chronic.parse(yesterday)
Chronic.parse(2010年1月20日)
您的问题类似于这个一个。
Is there some intelligent date / time parser library for Java? By intelligent I mean, that I don't need to specify the date / time format. The API should be similar to this:
Calendar cal = DateTimeParser.parse("01/06/10 14:55");
cal = DateTimeParser.parse("1 Jan 2009"); // assumes 00:00 time
cal = DateTimeParser.parse("1.2.2010");
cal = DateTimeParser.parse("kygyutrtf"); // throws exception
UPDATE:
// I'm telling the parser: "If unsure, assume US date format"
cal = DateTimeParser.parse("01/02/03", new Locale("en-us"));
解决方案
JodaTime is excellent for manipulating date objects (e.g. date.plusDays(10))
...but JChronic is what you want for natural language date parsing, e.g.
Chronic.parse("now")
Chronic.parse("tomorrow 15:00")
Chronic.parse("14/2/2001")
Chronic.parse("yesterday")
Chronic.parse("20 Jan 2010")
Your question is similar to this one.
这篇关于Java的智能日期/时间解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文