赞
踩
获取系统时区:
- TimeZone timeZone = TimeZone.getDefault();
- String id = timeZone.getID(); //获取时区id,如“Asia/Shanghai”
- String name = timeZone.getDisplayName(); //获取名字,如“”
- String shotName = timeZone.getDisplayName(false, TimeZone.SHORT); //获取名字,如“GMT+08:00”
- int time = timeZone.getRawOffset(); //获取时差,返回值毫秒
获取系统支持所有时区id:
- String[] _id = TimeZone.getAvailableIDs();
- String id = null;
- for (int i = 0; i < _id.length; i++) {
- if (TimeZone.getTimeZone(_id[i]).getRawOffset() / 3600 / 1000 == -5) {
- //获取时差为-5的所有id
- //do something
- }
- }
设置默认时区:
- AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
- alarm.setTimeZone(id);//默认时区的id
- //alarm.setTimeZone("America/Atikokan");
设置默认时区需permission:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。