Android List All Timezone With Country, City and GMT Info (Kotlin)

Mar 28, 2020
val items = TimeZone.getAvailableIDs().map { id ->    // val timeZone = TimeZone.getTimeZone(id)    // val name = timeZone.displayName    val zone = ZoneId.of(id);    val offsetToday = OffsetDateTime.now(zone).offset    val offset = offsetFormatter.format(offsetToday)    // GMT    val tokens = id.replace("_", " ").split("/")    val name = if (tokens.size == 2) {        val (country, city) = tokens       "$city ($country)"    }    else id    TimezoneView(id, name = name, offsetName = offset, offset = offsetToday.totalSeconds)}
class TimezoneView(val id: String, val name: String, val offsetName: String, offset: Int)

Sample

Kuala Lumpur (Malaysia)     // name
GMT+8:00                    // offsetName
New York (United States)    // name
GMT-4:00                    // offsetName

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.