开发者

DateUtils.parseDate doesn't throw ParseException on invalid dates

开发者 https://www.devze.com 2023-01-21 02:06 出处:网络
java.util.date 开发者_运维技巧= org.apache.commons.lang.time.DateUtils.parseDate(value, new String[] { \"mm/dd/yyyy\" });

java.util.date 开发者_运维技巧= org.apache.commons.lang.time.DateUtils.parseDate(value, new String[] { "mm/dd/yyyy" });

If you give an invalid date string (e.g. value = 13/02/2000 or value = "12/35/2000"), this didn't result in an error (e.g. 13 as a month is invalid and 35 as a date is invalid). But the above function just moved the appropriate date | month bits and gave a date which was correct. Is there a function which will throw a ParseException in such cases?


DateUtils.parseDateStrictly(String, String[]) FTW!

0

精彩评论

暂无评论...
验证码 换一张
取 消