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

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...