-2

I am developing an app that will be used in Australia. I want to fix the timezone of device so that even if the user changes the timezone from Device setting, I will get Australia/Sydney Time Zone. My app should not be dependent of Device set time zone.

I looked for answers but unsuccessful. Whenever I am setting the Time Zone to Australia/Sydney it always returns the Current Location Time Zone.

Chandan kushwaha
  • 941
  • 6
  • 26

1 Answers1

2

One of causes could be that you didn't allow your app to change time zone. In your AndroidManifest.xml do you have this:

<uses-permission android:name="android.permission.SET_TIME_ZONE"/>

Another approach would be not to change time zone but change time format to extract time for different time zone:

Calendar calendar = Calendar.getInstance();       
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss z");
sdf.setTimeZone(TimeZone.getTimeZone("Australia/Sydney"));
String myTime=sdf.format(calendar.getTime());
Alex
  • 4,457
  • 2
  • 20
  • 59