Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Graph DateTimeTimeZone to LocaldateTime

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?

like image 392
S-Wing Avatar asked Jan 11 '18 09:01

S-Wing


People also ask

Why use DateTimeOffset instead of 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.

What is the difference between DateTimeOffset and DateTime?

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.

Is DateTimeOffset UTC?

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.


1 Answers

DateTimeTimeZone provides extension methods that take Datetime and timezone string, You can check by going into the definition of the class DateTimeTimeZoneExtensions

like image 127
Usman Khalid Avatar answered Sep 29 '22 16:09

Usman Khalid