7

What is the correct way of converting 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 internally calling each other?

lss
  • 1,235
  • 3
  • 15
  • 24
  • It is difficult to give a simple answer to this. If you decompile the code in mscorlib you can see how each are implemented and it is not a straightforward comparison – Justin Harvey Jul 12 '17 at 10:37

1 Answers1

6

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

The most obvious difference in their standard usage is that System.DateTime.ToLocalTime() uses a local timezone provided by the system, while TimeZoneInfo.ConvertTime() uses whatever timezone you give it (e.g. you hardcode CET).

In both cases you should pay attention to the Kind property, which can sometimes ruin your day.

Anyway, you might want to check this question and of course the MSDN documentation of both methods, which sums up their behavior quite well.

Michal S
  • 481
  • 4
  • 8