Trying to create an all-day event using Google Calendar API v3 for Java causes an error -
i can create timed event using java v3 google calendar api (as per sample code on google's website), need create all-day event.
i call event's setstart() , setend(), i.e.
event.setstart(starteventdatetime); event.setend(endeventdatetime);
these methods require , eventdatetime, i.e.
eventdatetime starteventdatetime = new eventdatetime().setdatetime(startdatetime); eventdatetime endeventdatetime = new eventdatetime().setdatetime(enddatetime);
i use setdatetime() methods setdate() causes 404 error.
setdatetime() requires com.google.api.client.util.datetime object, doing
datetime startdatetime = new datetime(startdate, timezone.gettimezone("utc")); datetime enddatetime = new datetime(enddate, timezone.gettimezone("utc"));
passing in timezone gives time element it's not day event.
i've tried setting dateonly true gives error:
datetime startdatetime = new datetime(true, startdate.gettime(), 0);
i can't other ways of creating datetime work: date date, timezone zone long value date value long value, integer tzshift string value
which way create datetime , can use setdate(), i.e. new eventdatetime().setdate(...)?
does have tested code snippet? why isn't documented google?
ps interestingly, when reading events google, using getdate() causes exception timed events , getdatetime() exception all-day events. need use getdate() all-day events , getdatetime() timed events.
fixed.
to create all-day event, must use setdate() having created datetime objects using string (which created formatting date objects). code:
date startdate = new date(); // or date database date enddate = new date(startdate.gettime() + 86400000); // all-day event 1 day (or 86400000 ms) long dateformat dateformat = new simpledateformat("yyyy-mm-dd"); string startdatestr = dateformat.format(startdate); string enddatestr = dateformat.format(enddate); // out of 6 methods creating datetime object no time element, string version works datetime startdatetime = new datetime(startdatestr); datetime enddatetime = new datetime(enddatestr); // must use setdate() method all-day event (setdatetime() used timed events) eventdatetime starteventdatetime = new eventdatetime().setdate(startdatetime); eventdatetime endeventdatetime = new eventdatetime().setdate(enddatetime); event.setstart(starteventdatetime); event.setend(endeventdatetime);
Comments
Post a Comment