Skip to content

Instantly share code, notes, and snippets.

@epaulsen
Created March 2, 2021 14:14
Show Gist options
  • Save epaulsen/479813304c46ab014acc70cd5d850935 to your computer and use it in GitHub Desktop.
Save epaulsen/479813304c46ab014acc70cd5d850935 to your computer and use it in GitHub Desktop.
DateTime.UtcNow decompiled
/// <summary>Gets a <see cref="T:System.DateTime" /> object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).</summary>
/// <returns>An object whose value is the current UTC date and time.</returns>
[__DynamicallyInvokable]
public static DateTime UtcNow
{
[SecuritySafeCritical, __DynamicallyInvokable] get
{
if (!DateTime.s_isLeapSecondsSupportedSystem)
return new DateTime((ulong) (DateTime.GetSystemTimeAsFileTime() + 504911232000000000L | 4611686018427387904L));
DateTime.FullSystemTime time = new DateTime.FullSystemTime();
DateTime.GetSystemTimeWithLeapSecondsHandling(ref time);
return DateTime.CreateDateTimeFromSystemTime(ref time);
}
}
[SecurityCritical]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern long GetSystemTimeAsFileTime();
[SecurityCritical]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool ValidateSystemTime(ref DateTime.FullSystemTime time, bool localTime);
[SecurityCritical]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void GetSystemTimeWithLeapSecondsHandling(
ref DateTime.FullSystemTime time);
[SecurityCritical]
[SuppressUnmanagedCodeSecurity]
[DllImport("QCall", CharSet = CharSet.Unicode)]
internal static extern bool IsLeapSecondsSupportedSystem();
[SecurityCritical]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool SystemFileTimeToSystemTime(
long fileTime,
ref DateTime.FullSystemTime time);
[SecurityCritical]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool SystemTimeToSystemFileTime(
ref DateTime.FullSystemTime time,
ref long fileTime);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment