How can i know time in a specific country if i am in a differenet country?

后端 未结 2 799
醉话见心
醉话见心 2021-01-25 07:34

I am trying to do it this way 1. Get my time current time and time zone. 2. I know time zone of that specific country from Google. 3. Calculate difference in time zones. 4. Subt

相关标签:
2条回答
  • 2021-01-25 08:23

    You can use Joda-Time library,

    Joda-Time User Guide

    http://www.joda.org/joda-time/

    How can i know time in a specific country if i am in a differenet country?

    http://www.joda.org/joda-time/apidocs/index.html

    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"));
    

    here it is explained very perfectly which is my reference to your question

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

    and you can also use this link without getting use of api

    http://tutorials.jenkov.com/java-date-time/java-util-timezone.html

    other references

    How to get time with respect to another timezone in android

    Date and time conversion to some other Timezone in java

    How to convert date time from one time zone to another time zone

    0 讨论(0)
  • 2021-01-25 08:37

    x is the time zone id, there are a link of a list of them. Only need to feed the gettimeZone("with the time zone id") with the time zone of the city you want to know the time (I'm saying city because there are country with a lot of time zones like US or Russia).

    TimeZone tz = TimeZone.getTimeZone("x")

    http://garygregory.wordpress.com/2013/06/18/what-are-the-java-timezone-ids/

    0 讨论(0)
提交回复
热议问题