IllegalArgumentException on Calendar.getTime() when lenient is false

时光怂恿深爱的人放手 提交于 2020-04-16 02:32:21

问题


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 Stack:

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)

Any ideas?

More details after first response: Timezone is CEST Java is 1.8.0_102 (the problem is also on IBM 1.6_x)


回答1:


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



来源:https://stackoverflow.com/questions/43214838/illegalargumentexception-on-calendar-gettime-when-lenient-is-false

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!