Reputation: 2989
I'm developing an application for android that has to list activities with its date and time. I would like to ignore the time zone of the device and show always the time in timezone +02:00.
The application is for Spain, but If someone from UK that is in another time zone use the application I want that the time for activities appear in local spanish time.
The date is in UTC format, using Calendar.getTime().toLocaleString(), the time appers in local time zone of device.
I would like to know if the is a way to set a default time zone that has to use my application, and when I invoke Calendar.getTime().toLocaleString() method get the time always in local time zone +2 despite of the device timezone
Upvotes: 3
Views: 11490
Reputation: 1381
TimeZone.setDefault(TimeZone.getTimeZone("GMT+3"));
This sets the default timezone. Subsequent calls to Calendar.getInstance()
always return as if the device was in that timezone.
Upvotes: 9
Reputation: 16062
You need to set the time zone of your calendar. This can be done like this :
Calendar.setTimeZone(TimeZone timezone);
And then your calendar will work with a different time zone.
If you want to change the system time zone this can be done by using setTimeZone()
of AlarmManager.
When doing that the manifest has to contain the right permission, which is
android.permission.SET_TIME
Link to Documentation
And there is some other solution i found Here, check it out.
Upvotes: 0