如何从特定日期的本机日历中获取事件

时间:2012-03-09 09:52:46

标签: blackberry calendar blackberry-jde

我正在尝试从本机日历中获取用户给出的日期的事件,我无法获取特定的事件日期。我该怎么办?

  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.LOCATION) && event.countValues(Event.LOCATION) > 0) {
                    String location = event.getString(Event.LOCATION, 0); 
                    Dialog.alert(location);
               }
                if(eventList.isSupportedField(Event.SUMMARY) && event.countValues(Event.SUMMARY) > 0) {
                    String subject = event.getString(Event.SUMMARY, 0); 
                    Dialog.alert(subject);
               }
               if(eventList.isSupportedField(Event.START) && event.countValues(Event.START) > 0) {
                    long start = event.getDate(Event.START,0); 
                    SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy HH:mm");
                    String dateString = sdf.formatLocal(start);
                    Dialog.alert(dateString);

               }
                 if(eventList.isSupportedField(Event.END)&& event.countValues(Event.END) > 0) {
                    long end = event.getDate(Event.END, 0); 
                    SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy HH:mm");
                    String dateString = sdf.formatLocal(end);
                    Dialog.alert(dateString);
               }

           }

           }
           catch (PIMException e) {
               Dialog.alert(e.getMessage());
            }

        }

如何修改要在给定日期显示的代码?

1 个答案:

答案 0 :(得分:2)

怎么样:

Calendar cal = Calendar.getInstance();
cal.setTimeMillis(start);
if (cal.get(Calendar.YEAR) == requestedYear && cal.get(Calendar.MONTH) == requestedMonth && cal.get(Calendar.DAY) == requestedDay) {
  // display event
}