summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/DateTime.CoreCLR.cs
blob: 69c595663b27b0b91e1d4b11a8bc30fb07feed38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;

namespace System
{
    public partial struct DateTime
    {
        public static DateTime UtcNow
        {
            get
            {
                Contract.Ensures(Contract.Result<DateTime>().Kind == DateTimeKind.Utc);
                // following code is tuned for speed. Don't change it without running benchmark.
                long ticks = 0;
                ticks = GetSystemTimeAsFileTime();

                return new DateTime(((UInt64)(ticks + FileTimeOffset)) | KindUtc);
            }
        }


        [MethodImplAttribute(MethodImplOptions.InternalCall)]
        internal static extern long GetSystemTimeAsFileTime();
    }
}