ERROR - java.time.DateTimeException: Zone offset hours not in valid range: value 20 is not in the range -18 to 18

Error

java.time.DateTimeException: Zone offset hours not in valid range: value 20 is not in the range -18 to 18
    at java.time.ZoneOffset.validate(ZoneOffset.java:364)
    at java.time.ZoneOffset.ofHoursMinutesSeconds(ZoneOffset.java:317)
    at java.time.ZoneOffset.ofHours(ZoneOffset.java:283)


Error Type

Run Time

Sample Code

ZonedDateTime zonedDatetime1 = ZonedDateTime.ofLocal(localDateTime,  ZoneId.of("UTC+05:30"), ZoneOffset.ofHours(20));
       

Cause

ZoneOffset should be in the range between -18 to 18

Resolution

Change the ZoneOffset to be within the specified range.

ZonedDateTime zonedDatetime1 = ZonedDateTime.ofLocal(localDateTime, ZoneId.of("UTC+05:30"), ZoneOffset.ofHours(15));