在我的日历中,时间显示为 IST
在我使用 Google 日历 API 的应用程序中,我得到了 GMT 时间
如何获取 IST 中的事件时间,即 GMT+05.30
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/