Android的日历全天事件日期将推后一个日子GMT + X区 [英] Android Calendar All Day event dates are off by one day for GMT +x Areas

查看:568
本文介绍了Android的日历全天事件日期将推后一个日子GMT + X区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的code插入一个全天事件到日历,使用教程从官方网站。 <一href="http://developer.android.com/guide/topics/providers/calendar-provider.html">http://developer.android.com/guide/topics/providers/calendar-provider.html

I wrote a simple code to insert an all day event into the calendar, using the tutorial from the official site. http://developer.android.com/guide/topics/providers/calendar-provider.html

    ContentResolver cr = context.getContentResolver();
    ContentValues values = new ContentValues();
    values.put(Events.DTSTART, dueDate.getTime());
    values.put(Events.ALL_DAY, true);   
    values.put(Events.DTEND, dueDate.getTime());
    values.put(Events.TITLE, "Some Event");
    values.put(Events.CALENDAR_ID, mCalID);
    TimeZone tz = TimeZone.getDefault();
    values.put(Events.EVENT_TIMEZONE, tz.getID());
   Uri uri = cr.insert(Events.CONTENT_URI, values);

我发现,当我打开运行4.03的我的宏碁设备上的谷歌日历应用程序,输入的日期已经后移1天。我的本地时区是悉尼是GMT + 10。

I found that when I opened the Google Calendar app on the my Acer device running 4.03, the date entered had been shifted back by 1 day. My local timezone is Sydney which is GMT+10.

于是我去设置本地时区更改为美国东部(北京时间),并运行相同的code和存在的日期,无移位。然后,我改变了时区为GMT + 2,伊斯坦布尔和存在的日期的转变。然后,我改变了伦敦格林威治时间0,也没有改变。

So I went to settings changed the local time zone to American Eastern (GMT -5) and ran the same code and there was no shift in the dates. Then I changed the timezone to GMT+2, Istanbul and there was a shift in the dates. Then I changed to London GMT 0, and there was no shift.

当我做不正确的时间被输入到日历全天事件不管时区的。

When I did non all day events the correct times were entered into the calendar regardless of the timezone.

最近的bug报告,我发现是这样的 <一href="http://$c$c.google.com/p/android/issues/detail?id=14051">http://$c$c.google.com/p/android/issues/detail?id=14051

The closest bug report I found was this http://code.google.com/p/android/issues/detail?id=14051

我缺少的东西在code,或有其他人也遇到了这个。

Am I missing something in the code, or have others also encountered this.

修改 在进一步的检查看使用内容解析事件数据时

Edit On further inspection when reading Event data using content resolver

  ContentResolver cr = context.getContentResolver();
Uri uri =  CalendarContract.Events.CONTENT_URI; 
String selection =CalendarContract.Events._ID + "=?";
String [] selectionArgs = new String[]{String.valueOf(eventID)}; 

在转换日的长期价值为正确的日期和时间,例如。 2013年2月14日12.00 AEST(悉尼时间)。因此,这个问题必须在谷歌日历中读取这些值的方式。当我手动从Android的日历应用程序添加一整天的活动,并利用内容解析器读取时间是日期和11:00 AEST中(悉尼时间),对应于+11 GMT关闭在悉尼成立。 因此,需要一整天的事件在格林尼治标准​​时间,以避免这种情况被输入,但文件中没有提到这一点。

The value of the long when convert to date was the correct date and time eg. 14th Feb 2013 12.00 AEST (Sydney Time). So the problem must be in the way Google Calendar is reading in these values. When I added an all day event manually from the Calendar application in Android, and the read the time using content resolver it was the date and 11.00 am in AEST (Sydney Time), which corresponds to the +11 GMT off set in Sydney. So all day events need to be entered in GMT to avoid this, but there is no mention of this in the documentation.

所以现在我转向的时候,要避免这个问题。

So now I am shifting the time, to avoid this problem.

推荐答案

一对夫妇的想法:

  1. 在时区全天活动的独立(视为具有GMT)[1] [2]
  2. 在国际日期变更线

[1]。如果allDay被设置为1 eventTimezone必须TIMEZONE_UTC和时间必须对应于午夜边界。

[1]"If allDay is set to 1 eventTimezone must be TIMEZONE_UTC and the time must correspond to a midnight boundary."

[2]的http://developer.android.com/reference/android/provider/CalendarContract.Events.html

这篇关于Android的日历全天事件日期将推后一个日子GMT + X区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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