When I get a date (of event or task) from Graph API it is saved in an instance of DateTimeTimeZone class. This object is composed by 2 properties ( datetime and timezone ) that are strings, and rapresent a UTC date. Is there a way to convert this "date" to local DateTime?
DateTime values lack any knowledge of time zone, or lack thereof. If you need to know when things actually occurred, with more precision than just the approximate date, and you can't be 100% sure that your dates are ALWAYS stored in UTC, then you should consider using DateTimeOffset to represent your datetime values.
With its Kind property, DateTime is able to reflect only Coordinated Universal Time (UTC) and the system's local time zone. DateTimeOffset reflects a time's offset from UTC, but it doesn't reflect the actual time zone to which that offset belongs.
The UtcDateTime property performs a dual conversion: It converts the date and time of the current DateTimeOffset object to Coordinated Universal Time (UTC). The conversion is performed by subtracting the value of the Offset property from the date and time of the current DateTimeOffset object.
DateTimeTimeZone
provides extension methods that take Datetime and timezone string, You can check by going into the definition of the class DateTimeTimeZoneExtensions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With