Is it possible to get the timezone I'm currently in? I need to convert local times to UTC and I might be in any timezone when that happens. The system knows the current timezone - does Automagic have a way to get it?
Thanks!
Get the Current Timezone?
Moderator: Martin
Re: Get the Current Timezone?
My timezone is IST.
To get current time in UTC
Code: Select all
tz="{0, dateformat, hh:mm}" //05:30
Code: Select all
tz=callJavaMethod(callJavaStaticMethod("java.util.TimeZone", "getDefault()"), "java.util.TimeZone", "getDisplayName()"); //India Standard Time
Code: Select all
tz=callJavaMethod(callJavaStaticMethod("java.util.TimeZone", "getDefault()"), "java.util.TimeZone", "getDisplayName(boolean, int)", false, getJavaStaticField("java.util.TimeZone", "SHORT")); //IST
Code: Select all
tz=callJavaMethod(callJavaStaticMethod("java.util.TimeZone", "getDefault()"), "java.util.TimeZone", "getID()"); //Asia/Kolkata
Code: Select all
{getDate(),dateformat,timezone,UTC,HH:mm}"
Re: Get the Current Timezone?
Ah, thanks. This is much shorter. If I only need to get the hour, I simply change the hh:mm to h only. But this is risky for timezone that has 30 minutes.anuraag wrote:Code: Select all
tz="{0, dateformat, hh:mm}" //05:30
I used to use this
Code: Select all
tz = -getDate("{0,dateformat,z}", "z");
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: Get the Current Timezone?
Thanks, anuraag, those are perfect, especially this one:
anuraag wrote:Code: Select all
tz=callJavaMethod(callJavaStaticMethod("java.util.TimeZone", "getDefault()"), "java.util.TimeZone", "getDisplayName(boolean, int)", false, getJavaStaticField("java.util.TimeZone", "SHORT")); //IST
Re: Get the Current Timezone?
Alternative posted by Desmanto If you need that onlypiz wrote:Thanks, anuraag, those are perfect, especially this one:anuraag wrote:Code: Select all
tz=callJavaMethod(callJavaStaticMethod("java.util.TimeZone", "getDefault()"), "java.util.TimeZone", "getDisplayName(boolean, int)", false, getJavaStaticField("java.util.TimeZone", "SHORT")); //IST
Code: Select all
tz = "{0,dateformat,z}" //IST