嗨,我正在根据 datetime 检索事件。当我通过日期时间作为查询以从谷歌日历获取事件时低于异常。
private static void dateRangeQuery(CalendarService service) throws ServiceException,
IOException {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH:mm");
//get current date time with Date()
Date date = new Date();
System.out.println(dateFormat.format(date));
//get current date time with Calendar()
Date dt = Calendar.getInstance().getTime();
//System.out.println(dateFormat.format(cal.getTime()));
// System.out.println(cal.getTime());
DateTime startTime = DateTime.parseDateTime(dateFormat.format(dt));
Calendar cal2 = Calendar.getInstance();
cal2.add(Calendar.MINUTE, 20);
System.out.println(dateFormat.format(cal2.getTime()));
System.out.println(cal2.getTime());
DateTime endTime = DateTime.parseDate(dateFormat.format(cal2.getTime()));
CalendarQuery myQuery = new CalendarQuery(eventFeedUrl);
myQuery.setMinimumStartTime(startTime);
myQuery.setMaximumStartTime(endTime);
// Send the request and receive the response:
CalendarEventFeed resultFeed = service.query(myQuery,
CalendarEventFeed.class);
//System.out.println("Events from " + startTime.toString() + " to "
// + endTime.toString() + ":");
System.out.println();
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
CalendarEventEntry entry = resultFeed.getEntries().get(i);
System.out.println("\t" + entry.getTitle().getPlainText());
}
System.out.println();
}
以下例外:
Exception in thread "main" java.lang.NumberFormatException: Invalid date/time format.
at com.google.gdata.data.DateTime.parseDateTime(DateTime.java:303)
at GoogleCalender.dateRangeQuery(GoogleCalender.java:185)
at GoogleCalender.main(GoogleCalender.java:115)
请任何人都可以建议如何解决这个问题