DateTimeOffset.UtcNow 属性    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个 DateTimeOffset 对象,其日期和时间设置为当前的协调世界时 (UTC) 日期和时间,其偏移量为 Zero。
public:
 static property DateTimeOffset UtcNow { DateTimeOffset get(); };public static DateTimeOffset UtcNow { get; }static member UtcNow : DateTimeOffsetPublic Shared ReadOnly Property UtcNow As DateTimeOffset属性值
一个对象,其日期和时间为当前的协调世界时 (UTC),其偏移量为 Zero。
示例
以下示例演示协调世界时 (UTC) 与本地时间之间的关系。
DateTimeOffset localTime = DateTimeOffset.Now;
DateTimeOffset utcTime = DateTimeOffset.UtcNow;
Console.WriteLine("Local Time:          {0}", localTime.ToString("T"));
Console.WriteLine("Difference from UTC: {0}", localTime.Offset.ToString());
Console.WriteLine("UTC:                 {0}", utcTime.ToString("T"));
// If run on a particular date at 1:19 PM, the example produces
// the following output:
//    Local Time:          1:19:43 PM
//    Difference from UTC: -07:00:00
//    UTC:                 8:19:43 PM
let localTime = DateTimeOffset.Now
let utcTime = DateTimeOffset.UtcNow
printfn $"Local Time:          {localTime:T}"
printfn $"Difference from UTC: {localTime.Offset}"
printfn $"UTC:                 {utcTime:T}"
// If run on a particular date at 1:19 PM, the example produces
// the following output:
//    Local Time:          1:19:43 PM
//    Difference from UTC: -07:00:00
//    UTC:                 8:19:43 PM
Dim localTime As DateTimeOffset = DateTimeOffset.Now
Dim utcTime As DateTimeOffset = DateTimeOffset.UtcNow
Console.WriteLine("Local Time:          {0}", localTime.ToString("T"))
Console.WriteLine("Difference from UTC: {0}", localTime.Offset.ToString())
Console.WriteLine("UTC:                 {0}", utcTime.ToString("T"))
' If run on a particular date at 1:19 PM, the example produces
' the following output:
'    Local Time:          1:19:43 PM
'    Difference from UTC: -07:00:00
'    UTC:                 8:19:43 PM
注解
属性 UtcNow 根据本地系统的时钟时间和本地系统时区定义的偏移量计算当前世界协调时 (UTC) 。
当前 UTC 时间的毫秒部分的精度取决于系统时钟的分辨率。 在 Windows NT 3.5 和更高版本以及 Windows Vista 操作系统上,时钟的分辨率大约为 10-15 毫秒。