gpt4 book ai didi

android - 如何获取重复事件的实时时间?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:47:55 25 4
gpt4 key购买 nike

我使用以下方法获取日历的所有事件:

public Cursor getEventsCursor(Context context) {        
long curr = System.currentTimeMillis();
long begin = curr - DateUtils.DAY_IN_MILLIS * 30; // - 30 days
long end = curr + DateUtils.DAY_IN_MILLIS * 30; // + 30 days

Cursor cur = null;
ContentResolver cr = context.getContentResolver();

String selection = Events.VISIBLE + "= ?";
String[] selectionArgs = new String[] {"1"};
String order = Events.DTSTART + " DESC";

Uri.Builder builder = Instances.CONTENT_URI.buildUpon();
ContentUris.appendId(builder, begin);
ContentUris.appendId(builder, end);

return cr.query(builder.build(), EVENT_PROJECTION,
selection, selectionArgs, order);
}

它有效,但我得到了所有重复事件的初始时间!

日志

Feeder milestone; eventId: 12;  date=2012-12-06 11:00:00  // initial time
Feeder milestone; eventId: 23; date=2012-12-06 11:00:00
Feeder milestone; eventId: 178; date=2012-12-06 11:00:00
Feeder milestone; eventId: 180; date=2012-12-06 11:00:00

如何获取重复事件的实时时间?

示例:如果重复事件 Feeder milestone 是 2 周一次的事件,我预计:

Feeder milestone; eventId: 12;  date=2014-08-03 11:00:00
Feeder milestone; eventId: 23; date=2014-08-27 11:00:00
Feeder milestone; eventId: 178; date=2014-09-11 11:00:00
Feeder milestone; eventId: 180; date=2014-09-25 11:00:00

最佳答案

来自 Calendar Provider documentation , 有 3 个与 Events 相关的东西,其中之一是 Instances

Events: This table holds the event-specific information. Each row in this table has the information for a single event—for example, event title, location, start time, end time, and so on. The event can occur one-time or can recur multiple times. Attendees, reminders, and extended properties are stored in separate tables. They each have an EVENT_ID that references the _ID in the Events table.

Instances: This table holds the start and end time for each occurrence of an event. Each row in this table represents a single event occurrence. For one-time events there is a 1:1 mapping of instances to events. For recurring events, multiple rows are automatically generated that correspond to multiple occurrences of that event.

(强调我的)

在重复事件的情况下,Events.DTSTART 指的是整个事件的开始时间。

另一方面,Instances.BEGINInstances.END 指的是事件每次发生 的开始和结束时间。

在一般情况下,始终使用Instances.BEGIN 来方便地获取所有事件(无论是否重复发生)的开始时间。

关于android - 如何获取重复事件的实时时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25734285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com