javaandroidkotlintimezonezoneid

Android - how to fix java.time.zone.ZoneRulesException: Unknown time-zone ID: Europe/Kyiv


I'm encountering an issue with timezones in my Android application (minSdkVersion = 26). I receive a list of time zones from a server, which includes "Europe/Kyiv". However, when I try to convert it to a ZoneId using ZoneId.of("Europe/Kyiv"), I get the following error: java.time.zone.ZoneRulesException: Unknown time-zone ID: Europe/Kyiv

I've read online that the IANA time zone identifier for Kyiv was updated from "Europe/Kiev" to "Europe/Kyiv" in late 2022.

My question is, what specific updates do I need to make to my project to successfully use ZoneId.of("Europe/Kyiv")?

I updated minSdk to 26, and it didn't help. Also, I have tried updating the Gradle JDK to 18+ and it doesn't work.


Solution

  • Time zone data (tzdata) updates are done by either Google or the OEM/ODM of the device.

    The Android Open Source Project has documentation on Android's time zone policy:

    https://source.android.com/docs/core/connect/time/time-zone-policy-recommendations

    and specifically on how to update time zone files:

    https://source.android.com/docs/core/permissions/timezone-rules

    Based on the comment thread, emulators appear not to be updated with any recent tzdata info, so most likely emulator Android OS is a snapshot of the AOSP at the time of release of a particular version.

    Should you need to get updated tzdata, perhaps on older no longer supported devices, you'll need to use a third-party library. Based on the comment in this question Update Android tzdata files, the library: https://github.com/dlew/joda-time-android may satisfy that need for getting tzdata changes but will require updating the library and your app as required, i.e. with some frequency.

    An alternate time library that has tzdata updates is ThreeTenABP but will still require the developer to use the most recent library which has time zone changes.