Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default time zone to use for an android application

Tags:

android

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

like image 932
Marc Cals Avatar asked Oct 20 '25 23:10

Marc Cals


1 Answers

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.

like image 183
Murat Ögat Avatar answered Oct 22 '25 13:10

Murat Ögat