I have a similar question to this one: How to strip timezone from DateTime in .NET Core, but I don’t want to use any string based parsings.
Basically I have events coming from various locations in the world with their timestamps collected with DateTime.Now
I want to report Events with their corresponding local creation timestamps (not utc).
So given that each datetime is basically represented like this:
2024-05-08T17:31:53.9744487+03:00
I want to extract just 2024-05-08T17:31:53.9744487
as a DateTime, so that I could report local time of the Event.
I don’t want to do any string parsing as in the answer above (or any string manipulations) as those are prone to errors.
So given this:
var originalDateTime = DateTime.Parse("2024-05-08T17:31:53.9744487+03:00");
How do you produce originalLocalDateTime (as a DateTime)?
This seems to be a surprisingly difficult problem to solve in C# as I couldn’t find anything working online.
Anybody knows how to solve it?