Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C添加Google日历事件时的时差问题#_C#_Timezone_Google Calendar Api_Gdata Api - Fatal编程技术网

C# 使用C添加Google日历事件时的时差问题#

C# 使用C添加Google日历事件时的时差问题#,c#,timezone,google-calendar-api,gdata-api,C#,Timezone,Google Calendar Api,Gdata Api,我正在使用“Google.GData.Calendar”API,使用c#将事件添加到Google日历中。但在MyDB和Google日历中创建的事件之间存在时间差 以下是使用Google.GData API将事件添加到Google日历的代码: publicstaticvoid AddEventToGoogle() { //字符串时区=“美国山区标准时间”; Uri postori=新Uri(“https://www.google.com/calendar/feeds/default/private

我正在使用“Google.GData.Calendar”API,使用c#将事件添加到Google日历中。但在MyDB和Google日历中创建的事件之间存在时间差

以下是使用Google.GData API将事件添加到Google日历的代码:

publicstaticvoid AddEventToGoogle()
{
//字符串时区=“美国山区标准时间”;
Uri postori=新Uri(“https://www.google.com/calendar/feeds/default/private/full");
尝试
{
GOAuthRequestFactory authFactory=新的GOAuthRequestFactory(“cl”、“MyApp”);
authFactory.ConsumerKey=ConfigurationManager.AppSettings[“GConsumerKey”].ToString();
authFactory.ConsumerCret=ConfigurationManager.AppSettings[“gconSumerKeyCret”].ToString();
authFactory.Token=“xxxxxxxxx”;
authFactory.TokenSecret=“xxxxxx”;
Google.GData.Calendar.CalendarService=new Google.GData.Calendar.CalendarService(authFactory.ApplicationName);
service.RequestFactory=authFactory;
EventEntry=新的EventEntry();
entry.Title.Text=“测试谷歌事件创建”;
entry.Content.Content=“测试谷歌事件创建”;
entry.Notifications=false;
When eventTime=new When();
eventTime.AllDay=false;
eventTime.StartTime=新的日期时间(2013,5,9,8,0,0);
eventTime.EndTime=新的日期时间(2013,5,9,11,0,0);
entry.Times.Add(eventTime);
//发送请求并接收响应:
EventEntry insertedEntry=service.Insert(postUri,entry);
if(insertedEntry!=null&&!string.IsNullOrEmpty(insertedEntry.EventId))
{
//获取insertedEntry.EventId
}
}
捕获(GDataRequestException gre)
{
HttpWebResponse=(HttpWebResponse)gre.response;
}
}
但是上面的代码与我打算创建的事件和Google日历中的条目存在时间差。我在谷歌日历上的时区是“(GMT-07:00)亚利桑那州山区时间”。当我把谷歌日历的时区改为CST,PST

请针对这种情况提出解决方案,或者在向Google日历添加事件时,我需要在哪里指定时区


用我用来添加事件的完整方法更新了我的问题

GData库使用了Google API的v2。我认为您需要将代码迁移到v3,以便获得对事件时区的适当支持

例如,请参见其中显示的创建重复事件的示例。(切换到“.NET”选项卡)

以下是一些可以帮助您的资源:

  • (但没有提到时区)
  • (请参见“.NET”选项卡)
我确实查阅了您的代码和v2 GData库的参考指南。我只在
日历条目
事件提要
、和
事件查询
类上看到了时区属性。由于您没有使用任何这些,我认为在v2中不可能实现

更新

这在v2 API中是可能的。您可以在ICAL格式的
标记中传递时区。请查看中示例后的注释


但是,在.Net GData客户端库中,它似乎没有作为
EventEntry
类的属性公开。因此,我的建议是-使用v3 api和客户端库。

您可以在将数据发布到api时发布数据吗?我不认为是您使用的语言导致了问题。而是日期。来自文档:“时间,作为组合日期时间值(根据RFC 3339格式化)。除非在“时区”中明确指定了时区,否则需要时区偏移量。”bvstone,请使用sampleMatt检查我的更新问题,感谢更新。我将检查可用样本,以将V2转换为V3。