我正在使用“Google.GData.Calendar”API 使用 c# 将事件添加到 Google 日历。但是在我的数据库和谷歌日历中创建的事件之间存在时间差异。
以下是使用 Google.GData API 将事件添加到 Google 日历的代码:
public static void AddEventToGoogle()
{
//string timezone = "US Mountain Standard Time";
Uri postUri = new Uri("https://www.google.com/calendar/feeds/default/private/full");
try
{
GOAuthRequestFactory authFactory = new GOAuthRequestFactory("cl", "MyApp");
authFactory.ConsumerKey = ConfigurationManager.AppSettings["GConsumerKey"].ToString();
authFactory.ConsumerSecret = ConfigurationManager.AppSettings["GConsumerKeySecret"].ToString();
authFactory.Token = "xxxxxxxxxx";
authFactory.TokenSecret = "xxxxxx";
Google.GData.Calendar.CalendarService service = new Google.GData.Calendar.CalendarService(authFactory.ApplicationName);
service.RequestFactory = authFactory;
EventEntry entry = new EventEntry();
entry.Title.Text = "Test Google Event Create";
entry.Content.Content = "Test Google Event Create";
entry.Notifications = false;
When eventTime = new When();
eventTime.AllDay = false;
eventTime.StartTime = new DateTime(2013, 5, 9, 8, 0, 0);
eventTime.EndTime = new DateTime(2013, 5, 9, 11, 0, 0);
entry.Times.Add(eventTime);
// Send the request and receive the response:
EventEntry insertedEntry = service.Insert(postUri, entry);
if (insertedEntry != null && !string.IsNullOrEmpty(insertedEntry.EventId))
{
//Get the insertedEntry.EventId
}
}
catch (GDataRequestException gre)
{
HttpWebResponse response = (HttpWebResponse)gre.Response;
}
}
但是对于上面的代码,我打算创建的事件和谷歌日历中的条目存在时间差异。我在 Google 日历中的时区是“(GMT-07:00) Mountain Time - Arizona”。当我将 Google 日历的时区更改为 CST、PST、...
请针对这种情况提出解决方法,或者在将事件添加到 Google 日历时我需要在哪里指定时区。
用我用来添加事件的完整方法更新了我的问题