Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

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 what will be the time in USA/New york and Tokyo.and Vice versa.

Any help is appreciable... Thank you

like image 668
Richa Avatar asked Feb 02 '12 07:02

Richa


2 Answers

please find the sollution below :

    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mma");
    TimeZone timezone = TimeZone.getDefault();
    TimeZone utcTimeZone = TimeZone.getTimeZone("UTC");
    Date d = new Date();
    sdf.setTimeZone(timezone);
    String strtime = sdf.format(d);
    Log.e("str time gmt  ",strtime);
    sdf.setTimeZone(utcTimeZone);
     strtime = sdf.format(d);
    Log.e("str time utc ",strtime);

i think this will solve your problem

like image 144
Ramesh Solanki Avatar answered Sep 30 '22 17:09

Ramesh Solanki


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

like image 39
Lalit Poptani Avatar answered Sep 30 '22 17:09

Lalit Poptani