How does DateTime.ToUniversalTime() work?

前端 未结 4 1692
北海茫月
北海茫月 2020-11-27 16:34

How does the conversion to UTC from the standard DateTime format work?

More specifically, if I create a DateTime object in one time zone an

4条回答
  •  余生分开走
    2020-11-27 17:01

    DateTime.ToUniversalTime removes the timezone offset of the local timezone to normalize a DateTime to UTC. If you then use DateTime.ToLocalTime on the normalized value in another timezone, the timezone offset of that timezone will be added to the normalized value for correct representation in that timezone.

提交回复
热议问题