Matthias
Matthias

Reputation: 33

IllegalArgumentException on Calendar.getTime() when lenient is false

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)

Upvotes: 1

Views: 3412

Answers (1)

Jigar Joshi
Jigar Joshi

Reputation: 240956

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

Upvotes: 5

Related Questions