converting timezone to 3 characters ZoneId

后端 未结 2 1004
面向向阳花
面向向阳花 2021-01-25 05:04

I want to convert TimeZone such as \"America/Chicago\" to \"CST\". I can make use of SHORT_IDS map of ZoneID class. However, there are limited number of timezones configured in

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-25 06:01

    Use TimeZone.getDisplayName:

    TimeZone.getTimeZone("America/Chicago").getDisplayName(false, TimeZone.SHORT)
    

    Ideone demo

    But be very careful about using three-letter time zone identifiers. Only use them for display (as implied by the method name); do not use them to identify a time zone otherwise.

提交回复
热议问题