Android Calendar时区未随CalendarContract更改 [英] Android Calendar timezone not changing with CalendarContract

查看:287
本文介绍了Android Calendar时区未随CalendarContract更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码将事件添加到日历中

I am using the following code to add an event to the calender

    Intent intent = new Intent(Intent.ACTION_INSERT);
    intent.setType("vnd.android.cursor.item/event");
    intent.putExtra(Events.TITLE, "my event title");
    intent.putExtra(Events.EVENT_LOCATION, "my city");
    intent.putExtra(Events.DESCRIPTION, "description of this event");

    intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, dep.getTimeInMillis());
    intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,  arr.getTimeInMillis());        

    intent.putExtra(CalendarContract.Events.EVENT_TIMEZONE, departureTimeZone);
    intent.putExtra(CalendarContract.Events.EVENT_END_TIMEZONE, arrivalTimeZone);

    // Making it private and shown as busy
    intent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE);
    intent.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    CoreApplication.getContext().startActivity(intent);

问题在于,拾音时间比原时间缩短了
一小时我发送并且
时区始终设置为设备的时区,例如欧洲中部夏令时+2

The problem is that the time it picks up is One Hour SHORTER than the original time i send and timezone is always set to device's timezone like "Central European Summer Time GMT +2"

请帮助!!!!! !!!!!!

HELP PLEASE!!!!!!!!!!!!!!!

推荐答案

遇到同样的麻烦,但找到了出路。

TimeZone集默认为设备的timeZone。若要更改此参数并将其设置为特定的timeZone,请使用getRawOffset()属性。

此方法计算当前时间的毫秒数。因此,您可以为指定的timeZone添加毫秒,然后减去默认timeZone的毫秒。


当我尝试将其更改为timeZone'GMT_ID'

Had the same trouble but found a way out.
TimeZone sets to the device's timeZone by default. To change this and to set it to a specific timeZone use the getRawOffset() property.
This method calculates the milliseconds from the current time. So you can add the milliseconds for your specified timeZone and subtract those for the default timeZone.

When I tried to change it to timeZone 'GMT_ID'

values.put(CalendarContract.Events.DTSTART, startDate.getTime()  +TimeZone.getTimeZone(GMT_ID).getRawOffset() -TimeZone.getDefault().getRawOffset());

希望这会有所帮助。

这篇关于Android Calendar时区未随CalendarContract更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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