无法从本机日历事件读取时间 [英] Not able to read the time from native calendar event
问题描述
我已经在黑莓日历中创建了特定日期和时间的appoitment,我试图使用以下代码读取日期和时间,但它显示错误。
I have created a appoitment for particular date and time in Blackberry calendar,i am trying to read date and time using the following code,but its showing the error.
private void getEvents() {
try {
EventList eventList = (EventList)PIM.getInstance().openPIMList(PIM.EVENT_LIST, PIM.READ_ONLY);
Enumeration events = eventList.items();
while (events.hasMoreElements()) {
Event event = (Event)events.nextElement();
if(eventList.isSupportedField(Event.ALARM) && event.countValues(Event.ALARM) > 0) {
long alarm = event.getDate(Event.ALARM, 0);
System.out.println(alarm);
}
}
}
我不确定if循环中有什么错误
i am not sure what is wrong in if loop
推荐答案
字段Event.ALARM包含:
The field Event.ALARM contains:
指定此事件的警报的相对时间的字段。
的数据此字段以INT数据类型表示。报警以秒为单位表示为
,并通过从该事件的每个
日期/时间减去报警值得到。例如,如果此字段的
值为600,则报警首先在Event.START指定的
日期/时间值之前600秒发生。对于
事件的重新出现,通过从特定事件发生的日期/时间的
减去存储的值来计算报警。
Field specifying a relative time for an Alarm for this Event. Data for this field is expressed with an INT data type. The alarm is expressed in seconds and derived by subtracting the alarm value from every date/time occurrence of this Event. For example, if this field has a value of 600, then the alarm first occurs 600 seconds before the date/time value specified by Event.START. For re-occurrences of the event, the alarm is calculated by subtracting the stored value from the date/time of the specific event occurrence.
因此,您需要从Event.START字段获取事件开始日期/时间的值。然后,您可以从开始日期/时间减去Event.ALARM的值(以秒为单位),以获取任何请求的提醒的时间。
So you need to get the value from the field Event.START for the Date/Time of the Event start. You can then subtract the value of Event.ALARM (as seconds) from the start Date/Time to get the time for any requested reminder.
long start = event.getDate(Event.START);
int alarm = event.getDate(Event.ALARM);
if (alarm > 0) {
long reminderTime = start - (long)alarm * 1000L;
...
}
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy HH:mm");
String dateString = sdf.formatLocal(start);
这篇关于无法从本机日历事件读取时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!