设置默认的时区用于Android应用程序 [英] Set default time zone to use for an android application

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

问题描述

我在开发Android有列出其日期和时间,活动的应用程序。我想忽略设备的时区,显示始终处于时区+02时间:00

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.

日期为UTC格式,使用Calendar.getTime()的toLocaleString(),时间appers在设备的本地时区。

The date is in UTC format, using Calendar.getTime().toLocaleString(), the time appers in local time zone of device.

我想知道,如果是设置有使用我的应用程序默认的时区的方式,当我调用Calendar.getTime()的toLocaleString()方法获取时间总在本地时区+2尽管该设备时区的

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

推荐答案

您需要设置你的日历的时区。
这可以这样进行:

You need to set the time zone of your calendar. This can be done like this :

Calendar.setTimeZone(TimeZone timezone);

和则您的日历将与不同的时区工作。

And then your calendar will work with a different time zone.

如果你想改变这可以通过使用 setTimeZone() AlarmManager的。

If you want to change the system time zone this can be done by using setTimeZone() of AlarmManager.

在这样做的清单必须包含正确的权限,这是

When doing that the manifest has to contain the right permission, which is

android.permission.SET_TIME

android.permission.SET_TIME

链接到<一个href=\"http://developer.android.com/reference/android/app/AlarmManager.html#setTimeZone%28java.lang.String%29\"相对=nofollow>文档

和有一些其他的解决办法,我发现<一个href=\"http://stackoverflow.com/questions/9755625/android-how-to-set-time-zone-through-application\">Here,检查出来。

And there is some other solution i found Here, check it out.

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

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