Returns the offset in milliseconds from UTC of this time zone's standard time.
Try to use Calendar and SimpleDateFormat instead, when you can. Let classes like Calendar and SimpleDateFormat do the date computations for you.
More usefully, the getOffset(int, int, int, int, int, int) methods return the actual offset from UTC for a given point in time; this is the raw offset plus (if the point in time is in daylight time) the applicable DST savings(usually, but not necessarily, 1 hour).
1. Initalize TimeZone object with the User's Preferred Time Zone with a TimeZone object named myTimeZone.
Toast.makeText(getBaseContext(),String.valueOf(myTimeZone.getRawOffset()), Toast.LENGTH_LONG).show();
More usefully, the getOffset(int, int, int, int, int, int) methods return the actual offset from UTC for a given point in time; this is the raw offset plus (if the point in time is in daylight time) the applicable DST savings(usually, but not necessarily, 1 hour).
1. Initalize TimeZone object with the User's Preferred Time Zone with a TimeZone object named myTimeZone.
2. To display the TimeZone Offset, you can display a Toast, such as below. It returns an integer so the String.valueOf() must be used to display to a toast. To save it to an integer variable, the String.valueOf() is not needed.
Toast.makeText(getBaseContext(),String.valueOf(myTimeZone.getRawOffset()), Toast.LENGTH_LONG).show();
3. Compile and run!
4. For me, in Central Standard Time, I get the below results displayed.
-21600000
5. This means I am located:
21,600,000 milliseconds from the UTC
-21600000
5. This means I am located:
21,600,000 milliseconds from the UTC
1 minute= 60,000 milliseconds
21,600,000/60,000 = 360 minutes (-360 minutes)
60 minutes = 1 hour
360/60 = 6 hours (-6 hours)
So, my Time Zone is 6 hours less than UTC.