How to get time with respect to another timezone in android

android, java, jodatime, timezone

Solution

In my opinion Time class is the best for your job. Also it is Android API not general Java API.

Here I mentioned some of useful methods for your job:

void switchTimezone(String timezone)

Convert this time object so the time represented remains the same, but is instead located in a different timezone.

static String getCurrentTimezone()

Returns the timezone string that is currently set for the device.

And if you want to save a time in a timezone independed manner, you can convert to milliseconds (in UTC) by `toMillis()` method and then retrieve it by `set(long millis)` method.

If something is unclear please tell me!

UPDATE

Example:

long timeMillis = /* get time milliseconds form the server */
Time time = new Time();
time.set(timeMillis);

/* changing time zone */
time.switchTimezone(/* your desired timezone in string format */);

/* getting time as string  */
String timeString = time.format("%Y%m%dT%H%M%S"); // you can change format as you wish

Here is a table for formatting times

Problem

I want to create an alarm application for FIFA 2014 world cup matches in which i have a server which stores the date and time for the matches in Brazil/Acre and my client is an android application and an android device may have any of the possible timezone so the my problem is i want to convert the Brazil/Acre timing to the local android device timing with different timezone and after lot of googled i came to know about joda data and time lib but it is too slow in android so please suggest any code that will work for me.

Original source

Related problems