Android how to set time zone through application

android, timezone

Solution

For Setting of the Time Zone Programetically you need to use the Date Class. See its Reference Documents here.

You need to use the `setTimeZone()` method of `SimpleDateFormat` Class.

Following is sample code for settings Time Zone of according to America

// First Create Object of Calendar Class
Calendar calendar = Calendar.getInstance();        
// Now Set the Date using DateFormat Class
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss z"); 
// Finally Set the time zone using SimpleDateFormat Class's setTimeZone() Method
sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); 

Problem

Android provides a permission called "SET_TIME_ZONE" with OS permission level "dangerous". Does anyone know that given an application with this permission, how can the app set the time zone ? Thanks.

Original source