Click here to Skip to main content
15,908,581 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have integrated google calendar v3 api in my mvc application and i am adding event by custom date and time.My application is hosted on Indian server and the the timezone for calendar is central time zone since the user lives in USA.SO whatever date i put in form and submit in calendar it always changes it to usa timing.
Please help me

What I have tried:


var folder = System.Web.HttpContext.Current.Server.MapPath("/App_Data/MyGoogleStorage");
           var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                           new ClientSecrets
                           {

                               ClientId = "xxxxxxxxx-xxxxxxx.apps.googleusercontent.com",
                               ClientSecret = "xxxxxxx",
                           },

                           new[] { CalendarService.Scope.Calendar },
                           "user",

                           CancellationToken.None,
                           new FileDataStore(folder)).Result;

           // Create the service.
           DateTime eventdate = Convert.ToDateTime(bdate);
           int evyear = eventdate.Year;
           int evmonth = eventdate.Month;
           int evday = eventdate.Day;

           DateTime eventtime = Convert.ToDateTime(btime);
           int evhour = eventtime.Hour;
           int evendhour = eventtime.Hour;
           int evmin = eventtime.Minute;
           int evendmin = evmin + 60;

           if (evendmin > 60)
           {
               evendmin = evendmin - 60;
               evendhour = evendhour + 1;
           }
           else if (evendmin == 60)
           {
               evendmin = 00;
               evendhour = evendhour + 1;
           }
           var service = new CalendarService(new BaseClientService.Initializer
           {
               HttpClientInitializer = credential,
               ApplicationName = "ANNA'S RESTAURANT",
           });

           var myEvent = new Event
           {
               Summary = "Name :" + Name + System.Environment.NewLine + "Person : " + pno,
               Description = "Phone No :" + phoneno + System.Environment.NewLine + "Special Request : " + srequest,
               Location = "607 Happy Valley Rd Glasgow , KY",

               Start = new EventDateTime
               {
                   DateTime = new DateTime(evyear, evmonth, evday, evhour, evmin, 0, 0),
                   TimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time").ToString()

               },
               End = new EventDateTime
               {
                   DateTime = new DateTime(evyear, evmonth, evday, evendhour, evendmin, 0, 0),
                   TimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time").ToString()

               },

           };

           var recurringEvent = service.Events.Insert(myEvent, "primary");
           recurringEvent.SendNotifications = true;
           recurringEvent.Execute();
Posted
Comments
Richard MacCutchan 8-Apr-17 3:48am    
You should always use UTC values for date and time types. You only need to convert them to local times when they are displayed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900