【问题标题】:How to get GMT/IST details from timezone object?如何从时区对象获取 GMT/IST 详细信息?
【发布时间】:2013-05-20 12:55:21
【问题描述】:

如何从时区对象中获取时区信息?

我有一个TimeZone java 对象,我需要显示如下信息

ex: IST - India Standard Time - (GMT+5.30)

我可以获得 IST - id 和显示名称(印度标准时间)和偏移量为 5:30

如何获得时区 - GMT ???

谢谢。

【问题讨论】:

    标签: java


    【解决方案1】:

    用于以zone-Id - zone-Name - (GMT standard offset) 格式显示

    1. 设置为所需时区

    2. 从上面的对象中获取所需的数据

    TimeZone tz = TimeZone.getTimeZone("Asia/Calcutta");

    tz.getID()              // for zone-id
    tz.getDisplayName()         // for zone-Name
    tz.getOffset(TimeZone.getDefault().getID()) // for GMT standard offset
    

    【讨论】:

      【解决方案2】:

      只需使用TimeZone.getTimeZone("GMT")。如果您想检查 ID 是否存在,请尝试使用TimeZone.getAvailableIDs()

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-12
        • 2018-01-19
        • 2022-08-19
        • 2014-10-15
        • 1970-01-01
        相关资源
        最近更新 更多