Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
617 views
in Technique[技术] by (71.8m points)

c# - Google Calendar Api v3 EventDateTime

I am trying to insert event in google calendar using google api v3 and getting error during insertion.I am using c#.

Error:

Google.Apis.Requests.RequestError

Invalid or mismatching start and end times. [400]

Errors [Message[Invalid or mismatching start and end times.] Location[ - ] Reason[invalid] Domain[global]

My code for EventDateTime is here.

            EventDateTime EventStartDTime = new EventDateTime();
            EventStartDTime.Date = "2013-06-03";
            EventStartDTime.DateTime = "2013-06-03T10:00:00.000+05:00";
            EventStartDTime.TimeZone = "Asia/Karachi";

            EventDateTime EventEndtDTime = new EventDateTime();
            EventEndtDTime.Date = "2013-06-05";
            EventEndtDTime.DateTime = "2013-06-05T10:00:00.000+05:00";
            EventEndtDTime.TimeZone = "Asia/Karachi";

Can Anyone help me to solve this issue?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Google calendar V3 API timestamp requires UTC format so you can mention datetime and timezone(optional) so you should provide the below format, which takes current timezone automatically:

            DateTime start = DateTime.Now;
            DateTime end = start + TimeSpan.FromMinutes(30);

            var curTZone = TimeZone.CurrentTimeZone;
            var dateStart = new DateTimeOffset(start, curTimeZone.GetUtcOffset(start));
            var dateEnd = new DateTimeOffset(end, curTimeZone.GetUtcOffset(end));
            var startTimeString = dateStart.ToString("o");
            var endTimeString = dateEnd.ToString("o");             

            evnt.Start = new EventDateTime()
            {                    
                DateTime = startTimeString 
            };

            evnt.End = new EventDateTime()
            {
                DateTime = endTimeString
            };

hope this help.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...