java - getting invalid date/time exception when getting events from google calender -
hi iam retrieving events based on datetime . when iam passing datetime query getting events google calender getting below exception.
private static void daterangequery(calendarservice service) throws serviceexception, ioexception { dateformat dateformat = new simpledateformat("yyyy-mm-dd-hh:mm"); //get current date time date() date date = new date(); system.out.println(dateformat.format(date)); //get current date time 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 request , receive response: calendareventfeed resultfeed = service.query(myquery, calendareventfeed.class); //system.out.println("events " + starttime.tostring() + " " // + endtime.tostring() + ":"); system.out.println(); (int = 0; < resultfeed.getentries().size(); i++) { calendarevententry entry = resultfeed.getentries().get(i); system.out.println("\t" + entry.gettitle().getplaintext()); } system.out.println(); }
exception below:
exception in thread "main" java.lang.numberformatexception: invalid date/time format. @ com.google.gdata.data.datetime.parsedatetime(datetime.java:303) @ googlecalender.daterangequery(googlecalender.java:185) @ googlecalender.main(googlecalender.java:115)
please can suggest how resolve issue
the xml datetime pattern, expected datetime.parsedatetime()
, [-]ccyy-mm-ddthh:mm:ss[z|(+|-)hh:mm]
.
so, date should formatted using simpledateformat yyyy-mm-dd't'hh:mm:ss
pattern (not tested).
but simpler way use datetime
constructor takes java.util.date
argument, instead of transforming date string, , thuis date datetime.
Comments
Post a Comment