An ICS file is a calendar file saved in Universal Calendar Format used by Email and Calendar Programs including Microsoft Outlook, Google Calendar, and Apple Calendar. It empowers clients to distribute and share Calendar Information on the web and over email. ICS documents are frequently utilized for sending meeting solicitations to different clients, who can import the occasions into their own particular timetables.
You can readily convert your ICS file into other formats like PDF, CVS XLSV etc.
In our previous blog we had shown you how to create an ICS file; in this blog we cover the time zone conversions which confuse a lot of developers.
There are some approaches online, but they did not seem graceful to us and ended up adding unnecessary IO operations to the code.
If you open your ICS file using text pad or any other such software, you would notice a DTSTART and a DTEND section of the format XXXXXXXXTXXXXXXZ. The section before T is the date and the section after T is Time.
The most important point to notice is that our machines have the capability of converting UTC to the local time zone. If we click on the date time settings we can clearly see how our time zone is with respect to the UTC.
- All you have to do it store the time in UTC and the system would be able to figure out things on its own.
- For this you have to be very careful as the time conversions are tricky and have to be tested with patience.
- As we use a drop down to select a custom time zone for our meetings (just like goggle calendar) the following code helps us get the time zone
TimeZoneInfo SelectedTimeZone = TimeZoneInfo.FindSystemTimeZoneById(radddlisttimezone.SelectedText);
where radddlisttimezone is a telerik dropdownlist.
startTime = radtimepickerstart.SelectedTime.Value;
starttimeUTC = new TimeSpan((new DateTime(startTime.Ticks).ToUniversalTime()).Ticks);
The above code helps converting this timezone time to UTC.
DateTime newstarttime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(startDate + startTime, SelectedTimeZone.Id, localtimeZoneinfo.Id);
starttimeUTC = TimeSpan.FromTicks(newstarttime.ToUniversalTime().TimeOfDay.Ticks);
The above code helps finding out the difference between the timezones and adjust, the second line helps convert the time to UTC which can directly be saved and used in the ics file.
You’re welcome as we are happy to help and subscribe to Dignitas Digital to get your queries solved.