【问题标题】:how to get the IST from google calendar using google API如何使用谷歌 API 从谷歌日历获取 IST
【发布时间】:2016-02-03 07:34:18
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:

    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 上添加了一个错误/功能请求

    【讨论】:

    • @DalmTo 我已经添加了图片,请看一次。 DateTimeRaw 是 IST 时间,而 DateTime 是 GMT。我的系统日期格式是 GMT。是因为系统时区吗?
    • 图片帮助我不得不去挖掘源代码:)
    • 哦,我为了问题请求偷了你的照片,希望你没问题。
    • 谢谢...请更新上述评论中的 github 链接。
    • 如果您的意思是下载日历 dll 源文件的日历。那个没有 GitHub 链接。各个 API 的 dll 是通过 Discovery API 和 python 脚本以编程方式生成的。它们不在 GitHub 上,您必须下载它们。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-04
    • 2013-12-13
    • 2016-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多