c# - 如何使用谷歌API从谷歌日历获取IST

标签 c# google-api google-calendar-api google-api-dotnet-client

在我的日历中,时间显示为 IST 在我使用 Google 日历 API 的应用程序中,我得到了 GMT 时间 如何获取 IST 中的事件时间,即 GMT+05.30

Please see this image

                request.TimeMin = dtStart;
                request.TimeMax = dtEnd;
                request.ShowDeleted = false;
                request.SingleEvents = true;
              //  request.TimeZone = "Asia/Calcutta";

最佳答案

Google .net 客户端库似乎正在与您的约会对象做一些有趣的事情。

从 Calendar v3 dll 中提取的代码

来源可以找到here

/// <summary>The date, in the format "yyyy-mm-dd", if this is an all-day event.</summary>
        [Newtonsoft.Json.JsonPropertyAttribute("date")]
        public virtual string Date { get; set; } 

        /// <summary>The time, as a combined date-time value (formatted according to RFC3339). A time zone offset is
        /// required unless a time zone is explicitly specified in timeZone.</summary>
        [Newtonsoft.Json.JsonPropertyAttribute("dateTime")]
        public virtual string DateTimeRaw { get; set; }

        /// <summary><seealso cref="System.DateTime"/> representation of <see cref="DateTimeRaw"/>.</summary>
        [Newtonsoft.Json.JsonIgnore]
        public virtual System.Nullable<System.DateTime> DateTime
        {
            get
            {
                return Google.Apis.Util.Utilities.GetDateTimeFromString(DateTimeRaw);
            }
            set
            {
                DateTimeRaw = Google.Apis.Util.Utilities.GetStringFromDateTime(value);
            }
        }

从核心库中窃取的代码 here

 /// <summary>
        /// Parses the input string and returns <see cref="System.DateTime"/> if the input is a valid 
        /// representation of a date. Otherwise it returns <c>null</c>.
        /// </summary>
        public static DateTime? GetDateTimeFromString(string raw)
        {
            DateTime result;
            if (!DateTime.TryParse(raw, out result))
            {
                return null;
            }
            return result;
        }

我的建议:

我建议您采用原始字符串 datetimeRaw 并自行将其转换为日期。我可能应该向客户端库添加一个问题,以将真实的日期转换添加到日期,而不是总是将其转换为本地时间。

我在客户端库上添加了错误/功能请求 [Calendar V3 generated] date cast to local time but not actual

关于c# - 如何使用谷歌API从谷歌日历获取IST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35171016/

相关文章:

c# - 定义局部变量 const 与类 const

c# - 如何支持 UWP InkCanvas 的多个手写笔输入?

c# - 程序集绑定(bind)重定向到较低版本

Android Pay - 完整的电子钱包确认结果代码 1 和错误代码 10

android - 在 Android 中使用谷歌翻译 API

javascript - 如何将 login_hint 传递给 gapi.auth.authorize?

c# - 用于 token 的 Google OAuth 数据存储

c# - 检查枚举是否包含多个标志

javascript - 将全天事件添加到 Google 日历的链接

google-api - 为什么我没有收到已删除或修改其实例之一的重复事件的 EXDATE?