Getting current GMT time

前端 未结 6 2094
鱼传尺愫
鱼传尺愫 2020-12-28 11:46

Is there a method in C# that returns the UTC (GMT) time zone? Not based on the system\'s time.

Basically I want to get the correct UTC time even if my system time is

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-28 12:41

    Instead of calling

    DateTime.Now.ToUniversalTime()
    

    you can call

    DateTime.UtcNow
    

    Same thing but shorter :) Documentation here.

提交回复
热议问题