【问题标题】:Timing issue when add the event to Google Calendar Event using C#?使用 C# 将事件添加到 Google 日历事件时的时间问题?
【发布时间】:2016-05-11 16:23:16
【问题描述】:

当我将事件添加到谷歌日历服务 URL 时,事件可以毫无错误地添加,但是当事件插入谷歌日历时它显示不同的时间,为什么它显示不同的时间,任何人帮助我解决这个问题,我给我的下面的代码。

            string location = "India Standard Time";
            string sdate = "5/12/2016 09:00:00 AM";
            string edate =  "5/12/2016 09:15:00 AM";
            string descri = "Sample";
            string sumary = "Sample";

            DateTime start = Convert.ToDateTime(sdate);
            DateTime? end = Convert.ToDateTime(edate);

            var dates = start.ToString("yyyyMMddTHHmmssZ");
            if (end.HasValue && end > start)
            {
                dates += "/" + end.Value.ToString("yyyyMMddTHHmmssZ");
            }
            else
            {
                dates += "/" + start.ToString("yyyyMMddTHHmmssZ");
            }

            string what = descri;
            string websiteName = descri;
            string websiteAddress = "****************************";

            string path = string.Format("http://www.google.com/calendar/event?action=TEMPLATE&text={0}&dates={1}&details={2}&location={3}&trp=false&sprop={4}&sprop=name:{5}",
                                    what,
                                    dates,
                                    sumary,
                                    location,
                                    websiteName,
                                    websiteAddress);                            

谢谢,
卡提克。

【问题讨论】:

  • 听起来您没有通过正确的时区。您的 toString 中的 Z 表示这将是 UTC。 location 字段不是时区的正确位置,它应该在 tz 参数中。

标签: c# google-calendar-api


【解决方案1】:

也许问题出在时区上。您可以查看documentation,了解如何在您的代码中设置/使用时区。

还要检查这个相关的 SO 问题:

【讨论】:

  • Karthik 没有使用 Calendar API,而是使用模板 Web UI 功能,其参数略有不同。
  • 感谢大家的宝贵信息,我得到了解决方案。
猜你喜欢
  • 2013-05-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-06
  • 1970-01-01
  • 2013-06-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多