2

After installing Android Things on a Raspberry Pi, time is not correct. My time zone is GMT+2, and using date +%Z I see RPi's time zone is GMT. How can I set time zone?

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
Sergio Viudes
  • 2,714
  • 5
  • 26
  • 44

2 Answers2

8

Update (based on Michal Harakal's comment):

Since Developer Preview 6 TimeManager class provides access to device settings related to time (NB! TimeManager requires <uses-permission android:name="com.google.android.things.permission.SET_TIME" />). You can use .setTimeZone() method of for time zone set:

private void setupTimeZone(String timeZoneName) {
    TimeManager timeManager = TimeManager.getInstance();
    timeManager.setTimeZone(timeZoneName);
}

where timeZoneName is one of tz database time zones string, e.g. for Kyiv (GMT +2, DST +3):

setupTimeZone("Europe/Kiev");

Original answer:

You can set it programmatically from Application via AlarmManager.setTimeZone() like in this answer of Synesso:

AlarmManager am = (AlarmManager)getContext().getSystemService(Context.ALARM_SERVICE);
am.setTimeZone("Europe/Madrid"); 

with <uses-permission android:name="android.permission.SET_TIME_ZONE"/> permission in AndroidManifest.xml file.

List of TimeZone names.

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
0

I use these codes

TimeManager timeManager = TimeManager.getInstance(); 
timeManager.setTimeFormat(TimeManager.FORMAT_24);
// Set time zone to Eastern Standard Time
//timeManager.setTimeZone("America/New_York");
timeManager.setTimeZone("GMT");
calendar.setTime(date);
long timeStamp = calendar.getTimeInMillis();
timeManager.setTime(timeStamp);

with this permission : com.google.android.things.permission.SET_TIME