Java有一个很好的日期解析器吗? [英] Is there a good date parser for Java?

查看:118
本文介绍了Java有一个很好的日期解析器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道一个很好的日期解析器为不同的语言/语言环境。 Java(SimpleDateFormat)的内置解析器非常严格。它应该在当前日期完成缺失的部分。



例如




  • 如果我没有进入年月),那么应该使用当年。

  • 如果年份为08,那么不应该解析0008,因为当前年份模式有4位数。



编辑:我想解析用户的输入。例如,如果用户的区域设置日期格式为dd.mm.yyyy,用户类型仅为12.11。那么解析器应该接受这个值为有效日期,值为12.11.2008。目标是一个很好的可用性。

解决方案

检查Joda时间及其怪异格式化。 http://joda-time.sourceforge.net/userguide.html#Input_and_Output



Java 8包括JSR-310 ,这样也可以是一个解决方案。


Does anyone know a good date parser for different languages/locales. The built-in parser of Java (SimpleDateFormat) is very strict. It should complete missing parts with the current date.

For example

  • if I do not enter the year (only day and month) then the current year should be used.
  • if the year is 08 then it should not parse 0008 because the current year pattern has 4 digits.

Edit: I want to parse the input from a user. For example if the locale date format of the user is "dd.mm.yyyy" and the user type only "12.11." then the parser should accept this as a valid date with the value "12.11.2008". The target is a good usability.

解决方案

Check Joda Time, and its Freaky Formatters. http://joda-time.sourceforge.net/userguide.html#Input_and_Output

Java 8 includes JSR-310 so that could be a solution as well.

这篇关于Java有一个很好的日期解析器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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