的Andr​​oid如何通过应用程序设置时区 [英] Android how to set time zone through application

查看:93
本文介绍了的Andr​​oid如何通过应用程序设置时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android提供了一个名为SET_TIME_ZONE与操作系统权限级别危险的许可。有谁知道这个权限给定的应用程序,如何应用程序设置时区?

Android provides a permission called "SET_TIME_ZONE" with OS permission level "dangerous". Does anyone know that given an application with this permission, how can the app set the time zone ?

感谢。

推荐答案

有关设置时区Programetically你需要使用Date类。 看到它的参考文档这里

For Setting of the Time Zone Programetically you need to use the Date Class. See its Reference Documents here.

您需要使用的SimpleDateFormat 类的<​​code> setTimeZone()方法。

下面是示例code根据美国设置时区

Following is sample code for settings Time Zone of according to America

// First Create Object of Calendar Class
Calendar calendar = Calendar.getInstance();        
// Now Set the Date using DateFormat Class
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss z"); 
// Finally Set the time zone using SimpleDateFormat Class's setTimeZone() Method
sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); 

这篇关于的Andr​​oid如何通过应用程序设置时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆