Reputation: 179
In my calendar time shows are in IST
In my application using Google calendar API I am getting time in GMT
How to get events time in IST i.e GMT+05.30
request.TimeMin = dtStart;
request.TimeMax = dtEnd;
request.ShowDeleted = false;
request.SingleEvents = true;
// request.TimeZone = "Asia/Calcutta";
Upvotes: 2
Views: 462
Reputation: 116918
The Google .net client library appears to be doing some fun stuff with your date.
Code ripped from the Calendar v3 dll
Source can be found 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);
}
}
code ripped from core lib 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;
}
My Suggestion:
I suggest you take the raw string datetimeRaw and cast it to a date yourself. I should probably add an issue to the client lib to add a true date cast to date as well instead of always casting it to local time.
I added a bug / feature request on the client lib [Calendar V3 generated] date cast to local time but not actual
Upvotes: 2