you can use
var now = DateTime.UtcNow;
To convert an existing DateTime if it has timezone information, you can use DateTime.ToUniversalTime () . If you get an instance of DateTime, for example,
var localNow = DateTime.Now;
he will have time zone information. If you create it, for example. using a tick counter, it will not contain time zone information unless you explicitly provide it.
var unspecifiedNow = new DateTime(someTickCount);
It should be noted that the processing of time zones in .NET is not optimal. You can take a look at Noda Time ( Jon Skeet project) if you need to do something with time zones.
source share