How can I get the current time zone in my Android application? I tried to use this
Calendar cal = Calendar.getInstance( userConfig.locale); TimeZone tz = cal.getTimeZone();
But I am not getting the timezone from it. How can I display the timezone?
According to http://developer.android.com/reference/android/text/format/Time.html you should be using Time. getCurrentTimezone() to retrieve the current timezone of the device.
Call TimeZone. getAvailableIDs() to get the list of known timezones for your system. This permission is only allowed for system apps. on android api 26 and 27 receive this error: setTimeZone: Neither user 10087 nor current process has android.
I need to Calculate the TotalTime by subtracting the EndTime with StartTime. The Format of StartTime and EndTime is as like follows: StartTime = "08:00 AM"; EndTime = "04:00 PM"; TotalTime in Hours and Mins Format.
Use this
Calendar cal = Calendar.getInstance(); TimeZone tz = cal.getTimeZone(); Log.d("Time zone","="+tz.getDisplayName());
or you can also use the java.util.TimeZone
class
TimeZone.getDefault().getDisplayName()
String timezoneID = TimeZone.getDefault().getID(); System.out.println(timezoneID);
In my Console, it prints Asia/Calcutta
And any Date Format, I set it Like....
SimpleDateFormat sdf2 = new SimpleDateFormat("dd-MMM-yyyy"); sdf2.setTimeZone(TimeZone.getTimeZone(timezoneID));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With