Frage

I am basically trying to read a .vcs file in Android. It has timezone value in the below format:

TZ:+05:30

Now I want to get the timezone name corresponding to this value. Means in this case it would be Kolkata(India).

Is there any code to achieve this in android?

War es hilfreich?

Lösung

(I'm assuming you can parse the text into an offset easily enough.)

In general, you can't. Something like "+05:30" just represents an offset from UTC at one particular time. It doesn't express how the offset changes within the time zone across the year (or across history). For example, for some of the time the Europe/London time zone has the same offset as Africa/Casablanca - but not always.

Assuming this is associated with a specific date/time, you could use TimeZone.getAvailableIDs, iterate over all the time zones, check what the offset from UTC is at that particular instant (using TimeZone.getOffset(long)) and see which time zones have the right offset at the right time. There could be many such zones though.

If you don't have a specific date/time, it's even more ambiguous. You can use getRawOffset and getDSTSavings to see whether the target offset is either the standard or DST offset for any particular zone - although note that these calls assume that for a particular time zone, the DST offset and standard offset remain the same across history (which isn't always true).

Andere Tipps

        TimeZone tz = TimeZone.getTimeZone("GMT-06:00");

        String tzarr[] = TimeZone.getAvailableIDs(tz.getRawOffset());
        for(int i=0;i<tzarr.length;i++)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top