Get time of different Time zones on selection of time from time picker

后端 未结 5 1099
醉梦人生
醉梦人生 2021-01-03 03:38

I have an issue of converting selected hours and minutes to different time zones of countries. Supposing if i select 10 am in India then i want to know at 10 am in india wha

5条回答
  •  鱼传尺愫
    2021-01-03 04:18

    You can probably use Joda Time - Java date and time API. You can get the DateTimeZone depending on the Canonical ID defined in the Joda Time,

    DateTimeZone zone = DateTimeZone.forID("Asia/Kolkata");
    

    Joda Time has a complete list of Canonical ID from where you can get TimeZone depending on the Canonical ID.

    So, if you want to get the local time in New York at this very moment, you would do the following

        // get current moment in default time zone
        DateTime dt = new DateTime();
        // translate to New York local time
        DateTime dtNewYork = dt.withZone(DateTimeZone.forID("America/New_York"));
    

    For getting more idea you can refer Changing TimeZone

提交回复
热议问题