设置Android Things时区

Ser*_*des 2 settings timezone raspberry-pi3 android-things

在Raspberry Pi上安装Android Things后,时间不正确.我的时区是GMT + 2,使用date +%Z我看到RPi的时区是GMT.我该如何设置时区?

And*_*nko 8

更新(根据Michal Harakal的评论):

由于Developer Preview 6 TimeManager类提供了与时间相关的设备设置(NB!TimeManager要求<uses-permission android:name="com.google.android.things.permission.SET_TIME" />).您可以使用.setTimeZone()时区设置的方法:

private void setupTimeZone(String timeZoneName) {
    TimeManager timeManager = TimeManager.getInstance();
    timeManager.setTimeZone(timeZoneName);
}
Run Code Online (Sandbox Code Playgroud)

其中timeZoneName一个是tz数据库时区字符串,例如对于Kyiv(GMT + 2,DST +3):

setupTimeZone("Europe/Kiev");
Run Code Online (Sandbox Code Playgroud)

原始答案:

你可以从应用程序中以编程方式设置它,AlarmManager.setTimeZone()就像在Synesso的这个答案中一样:

AlarmManager am = (AlarmManager)getContext().getSystemService(Context.ALARM_SERVICE);
am.setTimeZone("Europe/Madrid"); 
Run Code Online (Sandbox Code Playgroud)

拥有文件<uses-permission android:name="android.permission.SET_TIME_ZONE"/>权限AndroidManifest.xml.

TimeZone名称列表.

  • 带有DP6的@cicciosgamino已经推出了一个用于设置时间的新API.查看TimeManager https://developer.android.com/things/reference/com/google/android/things/device/TimeManager.html (2认同)