如果lenient为false,则Calendar.getTime()上的IllegalArgumentException [英] IllegalArgumentException on Calendar.getTime() when lenient is false
本文介绍了如果lenient为false,则Calendar.getTime()上的IllegalArgumentException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的代码中,我收到一个IllegalArgumentException,但我不明白为什么:
In the following code I get a IllegalArgumentException but I can not understand why:
Calendar date = Calendar.getInstance();
date.clear();
date.setLenient(false);
date.set(2017, 2, 26, 2, 23);
date.getTime();//here is the Exception thrown
异常堆栈:
Exception in thread "main" java.lang.IllegalArgumentException: HOUR_OF_DAY: 2 -> 3
at java.util.GregorianCalendar.computeTime(GregorianCalendar.java:2829)
at java.util.Calendar.updateTime(Calendar.java:3393)
at java.util.Calendar.getTimeInMillis(Calendar.java:1782)
at java.util.Calendar.getTime(Calendar.java:1755)
at WildDog.main(WildDog.java:13)
有什么想法吗?
首次回复后的更多详细信息:
时区是CEST
Java是1.8.0_102(问题也在IBM 1.6_x上)
More details after first response: Timezone is CEST Java is 1.8.0_102 (the problem is also on IBM 1.6_x)
推荐答案
时间简直就是在给定时区存在。在此期间,大多数欧洲国家都经历了夏令时转换。按照@JonSkeet的建议找出您的时区并进行验证。您可能是CET-> CEST
Time simply doesn't exist for the given timezone. Most of the european countries goes through DST shift during this time. Find out your timezone as @JonSkeet suggested and validate it. Yours is probably CET --> CEST
这篇关于如果lenient为false,则Calendar.getTime()上的IllegalArgumentException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文