chuckd
chuckd

Reputation: 14540

Getting the correct date with seconds for my google calendar email link

I'm having a problem getting the correct date time for my google calendar link in an email I'm generating.

I'm generating the date string like this.

FormattedDateTime = String.Format("{0:yyyyMMdd}T{0:HHmmss}Z%2F{1:yyyyMMdd}T{1:HHmmss}Z", newEvent.EventDateTime, newEvent.EventDateTimeEnd))

and I end up getting a string like this

20170829T180000Z%2F20170829T190000Z

where the month, day and year look correct, but the seconds seem to be off and when I click on the link in my email and it opens up google calendar the day and time is off/not correct.

ex. I use the date and time 8/29/2017 @ 11:00AM to 12:00PM 8/29/2017 and I generate a string that looks like this

20170829T040000Z%2F20170829T050000Z

and it opens in google calendar with 8/28/2017 @ 9:00PM to 10:00PM 8/28/2017

so the day and time are off by a few hours.

if I use this link to generate the string for 8/29/2017 11:00AM to 12:00PM 8/29/2017 I get this

20170829T180000Z%2F20170829T190000Z

you can see the seconds are different. But it opens google calendar with the correct date and time.

So what am I doing wrong? I'm guessing google calendar should use whatever time zone it's in, right? Do I need to do some kind of time conversion here?

Upvotes: 0

Views: 184

Answers (1)

Mitya
Mitya

Reputation: 642

Looks like google calendar needs UTC time. Try

FormattedDateTime = String.Format("{0:yyyyMMdd}T{0:HHmmss}Z%2F{1:yyyyMMdd}T{1:HHmmss}Z", newEvent.EventDateTime.ToUniversalTime(), newEvent.EventDateTimeEnd.ToUniversalTime()))

Upvotes: 1

Related Questions