【问题标题】:Google Calender API - Create/Edit Event Times Not AccurateGoogle Calendar API - 创建/编辑事件时间不准确
【发布时间】:2022-01-07 14:09:33
【问题描述】:

我们正在尝试使用 .Net/C# 在 Google 日历中创建事件。当我们创建事件时,它们总是比预定时间晚 5 小时(例如,从 12:00 PM 到 11:59 PM 的事件变为上午 7:00 到下午 6:59)。

以下是我们创建事件的方式:

//creating new event object based off of the Google API Event type
            Event newEvent = new Event() {
                //assigning values for events
                Summary = (@event.bandName + " " + @event.eventStart.ToShortTimeString() + "-" + @event.eventEnd.ToShortTimeString() + " $" + @event.ticketPrice).ToUpper(),
                Description = bandLink + " " + @event.description,
                Start = new EventDateTime()
                {
                    DateTime = @event.eventStart
                },
                End = new EventDateTime()
                {
                    DateTime = @event.eventEnd
                },
                
            };

我们尝试过做类似的事情:

DateTime start = new DateTime(@event.eventStart, DateTimeKind.Local);

然后将此值分配给开始时间

Start = new EventDateTime()
                {
                    DateTime = start
                },

但我们仍然遇到最初的问题(从下午 12:00 到晚上 11:59 的事件变为上午 7:00 到下午 6:59)。

我们的摘要显示在谷歌日历中的正确时间,只有事件的开始/结束时间显示错误。

【问题讨论】:

    标签: c# .net timezone google-calendar-api


    【解决方案1】:

    根据documentation:

    开始日期时间

    时间,作为组合的日期时间值(根据 RFC3339 格式化)。 时区偏移是必需的,除非在 timeZone 中明确指定时区。

    这意味着您需要

    • 明确设置timeZone 属性或
    • 将时区偏移量合并到dateTime

    示例:

    Start = new EventDateTime()
     {
       DateTime = new DateTime(2021, 12, 01, 11, 11, 0),
       TimeZone = "America/Los_Angeles",
     }
    

    【讨论】:

      猜你喜欢
      • 2022-01-09
      • 1970-01-01
      • 2016-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多