ASP.NET Core DateTime - ToLocalTime vs ConvertTime

What is the correct way to convert UTC DateTime to local time (CET)? Should I use System.DateTime.ToLocalTime()

or TimeZoneInfo.ConvertTime()

? Are there any differences? Or are they just two methods that internally call each other?

+3


source to share


1 answer


Both methods should work fine, I don't think one is more correct than the other.

The most obvious difference in their standard usage is that it System.DateTime.ToLocalTime()

uses the local timezone provided by the system, while it TimeZoneInfo.ConvertTime()

uses whatever timezone you give it (e.g. hardcoded CET).



In both cases, you should pay attention to the property Kind

that can sometimes ruin your day.

Anyway, you can check this question and of course the MSDN documentation of both methods, which summarizes their behavior quite well.

+2


source







All Articles