.NET - System.DateTime (日期时间)

创建时间:
2014-11-30 00:16
最近更新:
2018-06-16 10:34

Vocabulary

  • nanosecond (金山词霸): n. 纳秒; 奈秒; 十亿分之一秒; 毫微秒。

Resource - MSDN

  1. DateTime 结构

Resource

  1. 谈谈你最熟悉的 System.DateTime - 蒋金楠

System.DateTime.Ticks 属性

MSDN

http://msdn.microsoft.com/zh-cn/library/system.datetime.ticks
http://msdn.microsoft.com/zh-CN/library/System.DateTime.Ticks(v=vs.90)

public long Ticks { get; }

Gets the number of ticks that represent the date and time of this instance (获取表示 此实例的日期和时间 的 计时周期 数).

A single tick represents one hundred nanoseconds or one ten-millionth of a second (单个 计时周期 表示 "100 纳秒" 或者 "千万分之一秒"). There are 10,000 ticks in a millisecond (一毫秒中有 10,000 个 计时周期), or 10 million ticks in a second (一秒中有 10,000,000 个 计时周期).

该值介于 DateTime.MinValue.Ticks (0) 和 DateTime.MaxValue.Ticks (3155378975999999999, 共 19 位) 之间。

每个 计时周期 表示 100纳秒,即 一千万分之一秒。此属性的值表示自 0001 年 1 月 1 日午夜 12:00:00 (表示 DateTime.MinValue) 以来经过的以 100 纳秒 为间隔的间隔数。

new DateTime(long ticks) 构造函数的参数按 DateTime.Ticks 的范围进行验证,超出范围 (例如 -1) 将抛出异常。

相关换算

100纳秒 即 1秒÷1000÷1000÷10。

  1,000,000,000 =                   10亿
1/1,000,000,000 = 0.000,000,001 =   10亿分之一

  10,000,000 =                  1千万
1/10,000,000 = 0.000,000,1 =    1千万分之一

System.DateTime.MinValue 字段 - MSDN

http://msdn.microsoft.com/zh-CN/library/System.DateTime.MinValue(v=vs.90)
表示 DateTime 的最小可能值。此字段为只读。
public static readonly DateTime MinValue
此常数的值等效于 0001 年 1 月 1 日 00:00:00.0000000。
DateTime.MinValue.Ticks 等于0。
MinValue 定义分配给未初始化的 DateTime 变量的日期和时间。
MinValueMaxValue 属性可用于确保值在传递给 DateTime 构造函数之前位于受支持的范围内。

System.DateTime.MaxValue 字段 - MSDN

http://msdn.microsoft.com/zh-CN/library/System.DateTime.MaxValue(v=vs.90)
表示 DateTime 的最大可能值。此字段为只读。
public static readonly DateTime MaxValue
此常数的值等效于 9999 年 12 月 31 日 23:59:59.9999999,恰好在 10000 年 1 月 1 日 00:00:00 之前一个 100 纳秒计时周期处。
DateTime.MaxValue.Ticks 等于 3155378975999999999 (共19位)。

Tony测试记录

long long0 = DateTime.MinValue.Ticks;//0
long long1 = DateTime.MaxValue.Ticks;//3155378975999999999(共19位)
long long2 = DateTime.MinValue.ToBinary();//0
long long3 = DateTime.MaxValue.ToBinary();//3155378975999999999(共19位)

DateTime now = DateTime.Now;
long long4 = now.Ticks;//634987152378976960(18位)
long long5 = now.ToBinary();//-8588385172475798848(19位)
Console.WriteLine(now == new DateTime(long4));//True
Console.WriteLine(now == new DateTime(long5));//抛出异常
Console.WriteLine(now == DateTime.FromBinary(long4));//True
Console.WriteLine(now == DateTime.FromBinary(long5));//True
Console.WriteLine(DateTime.FromBinary(long4) == DateTime.FromBinary(long5));//注意结果为True!

DateTime.MinValue等于new DateTime(0),两者的Ticks均为0。
DateTime.MaxValue大于new DateTime((long)10000 * 365 * 24 * 60 * 60 * 1000 * 1000 * 10),后者的365天丢失了闰年。
MSDN:
ulong数据类型的范围为0到18,446,744,073,709,551,615(共20位)。
DateTime 值类型表示值范围在公元(基督纪元)0001 年 1 月 1 日午夜 12:00:00 到公元 (C.E.) 9999 年 12 月 31 日晚上 11:59:59 之间的日期和时间。
从 .NET Framework 2.0 开始,DateTime 结构包含一个由私有字段 Kind 和 Ticks 字段串联组成的 64 位字段。Kind 字段是一个 2 位字段,Ticks 字段是一个 62 位无符号字段。
Tony总结:ulong甚至long的非负部分,都要比62位的DateTime.Ticks范围大。

源码分析

  • System.DateTime 结构中 只有 public int Millisecond { get { return (int) (this.InternalTicks / 10000L % 1000L); } } 系列用于获取 某部分 的值,没有 TotalMilliseconds 系列将 InternalTicks 进行换算。

Source Code of System.DateTime from JetBrains dotPeek 1.0 at 2018-06-13

Complete Copy:

// Type: System.DateTime
// Assembly: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll

using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security;

namespace System
{
  [__DynamicallyInvokable]
  [Serializable]
  [StructLayout(LayoutKind.Auto)]
  public struct DateTime : IComparable, IFormattable, IConvertible, ISerializable, IComparable<DateTime>, IEquatable<DateTime>
  {
    private static readonly int[] DaysToMonth365 = new int[13]
    {
      0,
      31,
      59,
      90,
      120,
      151,
      181,
      212,
      243,
      273,
      304,
      334,
      365
    };
    private static readonly int[] DaysToMonth366 = new int[13]
    {
      0,
      31,
      60,
      91,
      121,
      152,
      182,
      213,
      244,
      274,
      305,
      335,
      366
    };
    [__DynamicallyInvokable]
    public static readonly DateTime MinValue = new DateTime(0L, DateTimeKind.Unspecified);
    [__DynamicallyInvokable]
    public static readonly DateTime MaxValue = new DateTime(3155378975999999999L, DateTimeKind.Unspecified);
    private const long TicksPerMillisecond = 10000L;
    private const long TicksPerSecond = 10000000L;
    private const long TicksPerMinute = 600000000L;
    private const long TicksPerHour = 36000000000L;
    private const long TicksPerDay = 864000000000L;
    private const int MillisPerSecond = 1000;
    private const int MillisPerMinute = 60000;
    private const int MillisPerHour = 3600000;
    private const int MillisPerDay = 86400000;
    private const int DaysPerYear = 365;
    private const int DaysPer4Years = 1461;
    private const int DaysPer100Years = 36524;
    private const int DaysPer400Years = 146097;
    private const int DaysTo1601 = 584388;
    private const int DaysTo1899 = 693593;
    internal const int DaysTo1970 = 719162;
    private const int DaysTo10000 = 3652059;
    internal const long MinTicks = 0L;
    internal const long MaxTicks = 3155378975999999999L;
    private const long MaxMillis = 315537897600000L;
    private const long FileTimeOffset = 504911232000000000L;
    private const long DoubleDateOffset = 599264352000000000L;
    private const long OADateMinAsTicks = 31241376000000000L;
    private const double OADateMinAsDouble = -657435.0;
    private const double OADateMaxAsDouble = 2958466.0;
    private const int DatePartYear = 0;
    private const int DatePartDayOfYear = 1;
    private const int DatePartMonth = 2;
    private const int DatePartDay = 3;
    private const ulong TicksMask = 4611686018427387903UL;
    private const ulong FlagsMask = 13835058055282163712UL;
    private const ulong LocalMask = 9223372036854775808UL;
    private const long TicksCeiling = 4611686018427387904L;
    private const ulong KindUnspecified = 0UL;
    private const ulong KindUtc = 4611686018427387904UL;
    private const ulong KindLocal = 9223372036854775808UL;
    private const ulong KindLocalAmbiguousDst = 13835058055282163712UL;
    private const int KindShift = 62;
    private const string TicksField = "ticks";
    private const string DateDataField = "dateData";
    private ulong dateData;

    internal long InternalTicks
    {
      get
      {
        return (long) this.dateData & 4611686018427387903L;
      }
    }

    private ulong InternalKind
    {
      get
      {
        return this.dateData & 13835058055282163712UL;
      }
    }

    [__DynamicallyInvokable]
    public DateTime Date
    {
      [__DynamicallyInvokable] get
      {
        long internalTicks = this.InternalTicks;
        long num1 = 864000000000L;
        long num2 = internalTicks % num1;
        return new DateTime((ulong) (internalTicks - num2) | this.InternalKind);
      }
    }

    [__DynamicallyInvokable]
    public int Day
    {
      [__DynamicallyInvokable] get
      {
        return this.GetDatePart(3);
      }
    }

    [__DynamicallyInvokable]
    public DayOfWeek DayOfWeek
    {
      [__DynamicallyInvokable] get
      {
        return (DayOfWeek) ((this.InternalTicks / 864000000000L + 1L) % 7L);
      }
    }

    [__DynamicallyInvokable]
    public int DayOfYear
    {
      [__DynamicallyInvokable] get
      {
        return this.GetDatePart(1);
      }
    }

    [__DynamicallyInvokable]
    public int Hour
    {
      [__DynamicallyInvokable] get
      {
        return (int) (this.InternalTicks / 36000000000L % 24L);
      }
    }

    [__DynamicallyInvokable]
    public DateTimeKind Kind
    {
      [__DynamicallyInvokable] get
      {
        switch (this.InternalKind)
        {
          case 0UL:
            return DateTimeKind.Unspecified;
          case 4611686018427387904UL:
            return DateTimeKind.Utc;
          default:
            return DateTimeKind.Local;
        }
      }
    }

    [__DynamicallyInvokable]
    public int Millisecond
    {
      [__DynamicallyInvokable] get
      {
        return (int) (this.InternalTicks / 10000L % 1000L);
      }
    }

    [__DynamicallyInvokable]
    public int Minute
    {
      [__DynamicallyInvokable] get
      {
        return (int) (this.InternalTicks / 600000000L % 60L);
      }
    }

    [__DynamicallyInvokable]
    public int Month
    {
      [__DynamicallyInvokable] get
      {
        return this.GetDatePart(2);
      }
    }

    [__DynamicallyInvokable]
    public static DateTime Now
    {
      [__DynamicallyInvokable] get
      {
        DateTime utcNow = DateTime.UtcNow;
        bool isAmbiguousLocalDst = false;
        long ticks1 = TimeZoneInfo.GetDateTimeNowUtcOffsetFromUtc(utcNow, out isAmbiguousLocalDst).Ticks;
        long ticks2 = utcNow.Ticks + ticks1;
        if (ticks2 > 3155378975999999999L)
          return new DateTime(3155378975999999999L, DateTimeKind.Local);
        if (ticks2 < 0L)
          return new DateTime(0L, DateTimeKind.Local);
        else
          return new DateTime(ticks2, DateTimeKind.Local, isAmbiguousLocalDst);
      }
    }

    [__DynamicallyInvokable]
    public static DateTime UtcNow
    {
      [SecuritySafeCritical, __DynamicallyInvokable] get
      {
        return new DateTime((ulong) (DateTime.GetSystemTimeAsFileTime() + 504911232000000000L | 4611686018427387904L));
      }
    }

    [__DynamicallyInvokable]
    public int Second
    {
      [__DynamicallyInvokable] get
      {
        return (int) (this.InternalTicks / 10000000L % 60L);
      }
    }

    [__DynamicallyInvokable]
    public long Ticks
    {
      [__DynamicallyInvokable] get
      {
        return this.InternalTicks;
      }
    }

    [__DynamicallyInvokable]
    public TimeSpan TimeOfDay
    {
      [__DynamicallyInvokable] get
      {
        return new TimeSpan(this.InternalTicks % 864000000000L);
      }
    }

    [__DynamicallyInvokable]
    public static DateTime Today
    {
      [__DynamicallyInvokable] get
      {
        return DateTime.Now.Date;
      }
    }

    [__DynamicallyInvokable]
    public int Year
    {
      [__DynamicallyInvokable] get
      {
        return this.GetDatePart(0);
      }
    }

    static DateTime()
    {
    }

    [__DynamicallyInvokable]
    public DateTime(long ticks)
    {
      if (ticks < 0L || ticks > 3155378975999999999L)
        throw new ArgumentOutOfRangeException("ticks", Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadTicks"));
      this.dateData = (ulong) ticks;
    }

    private DateTime(ulong dateData)
    {
      this.dateData = dateData;
    }

    [__DynamicallyInvokable]
    public DateTime(long ticks, DateTimeKind kind)
    {
      if (ticks < 0L || ticks > 3155378975999999999L)
        throw new ArgumentOutOfRangeException("ticks", Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadTicks"));
      if (kind < DateTimeKind.Unspecified || kind > DateTimeKind.Local)
        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidDateTimeKind"), "kind");
      this.dateData = (ulong) (ticks | (long) kind << 62);
    }

    internal DateTime(long ticks, DateTimeKind kind, bool isAmbiguousDst)
    {
      if (ticks < 0L || ticks > 3155378975999999999L)
        throw new ArgumentOutOfRangeException("ticks", Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadTicks"));
      this.dateData = (ulong) (ticks | (isAmbiguousDst ? -4611686018427387904L : long.MinValue));
    }

    [__DynamicallyInvokable]
    public DateTime(int year, int month, int day)
    {
      this.dateData = (ulong) DateTime.DateToTicks(year, month, day);
    }

    public DateTime(int year, int month, int day, Calendar calendar)
    {
      this = new DateTime(year, month, day, 0, 0, 0, calendar);
    }

    [__DynamicallyInvokable]
    public DateTime(int year, int month, int day, int hour, int minute, int second)
    {
      this.dateData = (ulong) (DateTime.DateToTicks(year, month, day) + DateTime.TimeToTicks(hour, minute, second));
    }

    [__DynamicallyInvokable]
    public DateTime(int year, int month, int day, int hour, int minute, int second, DateTimeKind kind)
    {
      if (kind < DateTimeKind.Unspecified || kind > DateTimeKind.Local)
        throw new ArgumentException(Environment.GetResourceString("Argument_InvalidDateTimeKind"), "kind");
      this.dateData = (ulong) (DateTime.DateToTicks(year, month, day) + DateTime.TimeToTicks(hour, minute, second) | (long) kind << 62);
    }

    public DateTime(int year, int month, int day, int hour, int minute, int second, Calendar calendar)
    {
      if (calendar == null)
        throw new ArgumentNullException("calendar");
      this.dateData = (ulong) calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks;
    }

    [__DynamicallyInvokable]
    public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
    {
      if (millisecond < 0 || millisecond >= 1000)
      {
        string paramName = "millisecond";
        string key = "ArgumentOutOfRange_Range";
        object[] objArray = new object[2];
        int index1 = 0;
        // ISSUE: variable of a boxed type
        __Boxed<int> local1 = (ValueType) 0;
        objArray[index1] = (object) local1;
        int index2 = 1;
        // ISSUE: variable of a boxed type
        __Boxed<int> local2 = (ValueType) 999;
        objArray[index2] = (object) local2;
        string resourceString = Environment.GetResourceString(key, objArray);
        throw new ArgumentOutOfRangeException(paramName, resourceString);
      }
      else
      {
        long num = DateTime.DateToTicks(year, month, day) + DateTime.TimeToTicks(hour, minute, second) + (long) millisecond * 10000L;
        if (num < 0L || num > 3155378975999999999L)
          throw new ArgumentException(Environment.GetResourceString("Arg_DateTimeRange"));
        this.dateData = (ulong) num;
      }
    }

    [__DynamicallyInvokable]
    public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, DateTimeKind kind)
    {
      if (millisecond < 0 || millisecond >= 1000)
      {
        string paramName = "millisecond";
        string key = "ArgumentOutOfRange_Range";
        object[] objArray = new object[2];
        int index1 = 0;
        // ISSUE: variable of a boxed type
        __Boxed<int> local1 = (ValueType) 0;
        objArray[index1] = (object) local1;
        int index2 = 1;
        // ISSUE: variable of a boxed type
        __Boxed<int> local2 = (ValueType) 999;
        objArray[index2] = (object) local2;
        string resourceString = Environment.GetResourceString(key, objArray);
        throw new ArgumentOutOfRangeException(paramName, resourceString);
      }
      else
      {
        if (kind < DateTimeKind.Unspecified || kind > DateTimeKind.Local)
          throw new ArgumentException(Environment.GetResourceString("Argument_InvalidDateTimeKind"), "kind");
        long num = DateTime.DateToTicks(year, month, day) + DateTime.TimeToTicks(hour, minute, second) + (long) millisecond * 10000L;
        if (num < 0L || num > 3155378975999999999L)
          throw new ArgumentException(Environment.GetResourceString("Arg_DateTimeRange"));
        this.dateData = (ulong) (num | (long) kind << 62);
      }
    }

    public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar)
    {
      if (calendar == null)
        throw new ArgumentNullException("calendar");
      if (millisecond < 0 || millisecond >= 1000)
      {
        string paramName = "millisecond";
        string key = "ArgumentOutOfRange_Range";
        object[] objArray = new object[2];
        int index1 = 0;
        // ISSUE: variable of a boxed type
        __Boxed<int> local1 = (ValueType) 0;
        objArray[index1] = (object) local1;
        int index2 = 1;
        // ISSUE: variable of a boxed type
        __Boxed<int> local2 = (ValueType) 999;
        objArray[index2] = (object) local2;
        string resourceString = Environment.GetResourceString(key, objArray);
        throw new ArgumentOutOfRangeException(paramName, resourceString);
      }
      else
      {
        long num = calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks + (long) millisecond * 10000L;
        if (num < 0L || num > 3155378975999999999L)
          throw new ArgumentException(Environment.GetResourceString("Arg_DateTimeRange"));
        this.dateData = (ulong) num;
      }
    }

    public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar, DateTimeKind kind)
    {
      if (calendar == null)
        throw new ArgumentNullException("calendar");
      if (millisecond < 0 || millisecond >= 1000)
      {
        string paramName = "millisecond";
        string key = "ArgumentOutOfRange_Range";
        object[] objArray = new object[2];
        int index1 = 0;
        // ISSUE: variable of a boxed type
        __Boxed<int> local1 = (ValueType) 0;
        objArray[index1] = (object) local1;
        int index2 = 1;
        // ISSUE: variable of a boxed type
        __Boxed<int> local2 = (ValueType) 999;
        objArray[index2] = (object) local2;
        string resourceString = Environment.GetResourceString(key, objArray);
        throw new ArgumentOutOfRangeException(paramName, resourceString);
      }
      else
      {
        if (kind < DateTimeKind.Unspecified || kind > DateTimeKind.Local)
          throw new ArgumentException(Environment.GetResourceString("Argument_InvalidDateTimeKind"), "kind");
        long num = calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks + (long) millisecond * 10000L;
        if (num < 0L || num > 3155378975999999999L)
          throw new ArgumentException(Environment.GetResourceString("Arg_DateTimeRange"));
        this.dateData = (ulong) (num | (long) kind << 62);
      }
    }

    private DateTime(SerializationInfo info, StreamingContext context)
    {
      if (info == null)
        throw new ArgumentNullException("info");
      bool flag1 = false;
      bool flag2 = false;
      long num1 = 0L;
      ulong num2 = 0UL;
      SerializationInfoEnumerator enumerator = info.GetEnumerator();
      while (enumerator.MoveNext())
      {
        string name = enumerator.Name;
        if (!(name == "ticks"))
        {
          if (name == "dateData")
          {
            num2 = Convert.ToUInt64(enumerator.Value, (IFormatProvider) CultureInfo.InvariantCulture);
            flag2 = true;
          }
        }
        else
        {
          num1 = Convert.ToInt64(enumerator.Value, (IFormatProvider) CultureInfo.InvariantCulture);
          flag1 = true;
        }
      }
      if (flag2)
      {
        this.dateData = num2;
      }
      else
      {
        if (!flag1)
          throw new SerializationException(Environment.GetResourceString("Serialization_MissingDateTimeData"));
        this.dateData = (ulong) num1;
      }
      long internalTicks = this.InternalTicks;
      if (internalTicks < 0L || internalTicks > 3155378975999999999L)
        throw new SerializationException(Environment.GetResourceString("Serialization_DateTimeTicksOutOfRange"));
    }

    [__DynamicallyInvokable]
    public static DateTime operator +(DateTime d, TimeSpan t)
    {
      long internalTicks = d.InternalTicks;
      long num = t._ticks;
      if (num > 3155378975999999999L - internalTicks || num < -internalTicks)
        throw new ArgumentOutOfRangeException("t", Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic"));
      else
        return new DateTime((ulong) (internalTicks + num) | d.InternalKind);
    }

    [__DynamicallyInvokable]
    public static DateTime operator -(DateTime d, TimeSpan t)
    {
      long internalTicks = d.InternalTicks;
      long num = t._ticks;
      if (internalTicks - 0L < num || internalTicks - 3155378975999999999L > num)
        throw new ArgumentOutOfRangeException("t", Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic"));
      else
        return new DateTime((ulong) (internalTicks - num) | d.InternalKind);
    }

    [__DynamicallyInvokable]
    public static TimeSpan operator -(DateTime d1, DateTime d2)
    {
      return new TimeSpan(d1.InternalTicks - d2.InternalTicks);
    }

    [__DynamicallyInvokable]
    public static bool operator ==(DateTime d1, DateTime d2)
    {
      return d1.InternalTicks == d2.InternalTicks;
    }

    [__DynamicallyInvokable]
    public static bool operator !=(DateTime d1, DateTime d2)
    {
      return d1.InternalTicks != d2.InternalTicks;
    }

    [__DynamicallyInvokable]
    public static bool operator <(DateTime t1, DateTime t2)
    {
      return t1.InternalTicks < t2.InternalTicks;
    }

    [__DynamicallyInvokable]
    public static bool operator <=(DateTime t1, DateTime t2)
    {
      return t1.InternalTicks <= t2.InternalTicks;
    }

    [__DynamicallyInvokable]
    public static bool operator >(DateTime t1, DateTime t2)
    {
      return t1.InternalTicks > t2.InternalTicks;
    }

    [__DynamicallyInvokable]
    public static bool operator >=(DateTime t1, DateTime t2)
    {
      return t1.InternalTicks >= t2.InternalTicks;
    }

    [__DynamicallyInvokable]
    public DateTime Add(TimeSpan value)
    {
      return this.AddTicks(value._ticks);
    }

    private DateTime Add(double value, int scale)
    {
      long num = (long) (value * (double) scale + (value >= 0.0 ? 0.5 : -0.5));
      if (num <= -315537897600000L || num >= 315537897600000L)
        throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_AddValue"));
      else
        return this.AddTicks(num * 10000L);
    }

    [__DynamicallyInvokable]
    public DateTime AddDays(double value)
    {
      return this.Add(value, 86400000);
    }

    [__DynamicallyInvokable]
    public DateTime AddHours(double value)
    {
      return this.Add(value, 3600000);
    }

    [__DynamicallyInvokable]
    public DateTime AddMilliseconds(double value)
    {
      return this.Add(value, 1);
    }

    [__DynamicallyInvokable]
    public DateTime AddMinutes(double value)
    {
      return this.Add(value, 60000);
    }

    [__DynamicallyInvokable]
    public DateTime AddMonths(int months)
    {
      if (months < -120000 || months > 120000)
        throw new ArgumentOutOfRangeException("months", Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadMonths"));
      int datePart1 = this.GetDatePart(0);
      int datePart2 = this.GetDatePart(2);
      int day = this.GetDatePart(3);
      int num1 = datePart2 - 1 + months;
      int month;
      int year;
      if (num1 >= 0)
      {
        month = num1 % 12 + 1;
        year = datePart1 + num1 / 12;
      }
      else
      {
        month = 12 + (num1 + 1) % 12;
        year = datePart1 + (num1 - 11) / 12;
      }
      if (year < 1 || year > 9999)
        throw new ArgumentOutOfRangeException("months", Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic"));
      int num2 = DateTime.DaysInMonth(year, month);
      if (day > num2)
        day = num2;
      return new DateTime((ulong) (DateTime.DateToTicks(year, month, day) + this.InternalTicks % 864000000000L) | this.InternalKind);
    }

    [__DynamicallyInvokable]
    public DateTime AddSeconds(double value)
    {
      return this.Add(value, 1000);
    }

    [__DynamicallyInvokable]
    public DateTime AddTicks(long value)
    {
      long internalTicks = this.InternalTicks;
      if (value > 3155378975999999999L - internalTicks || value < -internalTicks)
        throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic"));
      else
        return new DateTime((ulong) (internalTicks + value) | this.InternalKind);
    }

    [__DynamicallyInvokable]
    public DateTime AddYears(int value)
    {
      if (value < -10000 || value > 10000)
        throw new ArgumentOutOfRangeException("years", Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadYears"));
      else
        return this.AddMonths(value * 12);
    }

    [__DynamicallyInvokable]
    public static int Compare(DateTime t1, DateTime t2)
    {
      long internalTicks1 = t1.InternalTicks;
      long internalTicks2 = t2.InternalTicks;
      if (internalTicks1 > internalTicks2)
        return 1;
      return internalTicks1 < internalTicks2 ? -1 : 0;
    }

    public int CompareTo(object value)
    {
      if (value == null)
        return 1;
      if (!(value is DateTime))
        throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDateTime"));
      long internalTicks1 = ((DateTime) value).InternalTicks;
      long internalTicks2 = this.InternalTicks;
      if (internalTicks2 > internalTicks1)
        return 1;
      return internalTicks2 < internalTicks1 ? -1 : 0;
    }

    [__DynamicallyInvokable]
    public int CompareTo(DateTime value)
    {
      long internalTicks1 = value.InternalTicks;
      long internalTicks2 = this.InternalTicks;
      if (internalTicks2 > internalTicks1)
        return 1;
      return internalTicks2 < internalTicks1 ? -1 : 0;
    }

    private static long DateToTicks(int year, int month, int day)
    {
      if (year >= 1 && year <= 9999 && (month >= 1 && month <= 12))
      {
        int[] numArray = DateTime.IsLeapYear(year) ? DateTime.DaysToMonth366 : DateTime.DaysToMonth365;
        if (day >= 1 && day <= numArray[month] - numArray[month - 1])
        {
          int num = year - 1;
          return (long) (num * 365 + num / 4 - num / 100 + num / 400 + numArray[month - 1] + day - 1) * 864000000000L;
        }
      }
      throw new ArgumentOutOfRangeException((string) null, Environment.GetResourceString("ArgumentOutOfRange_BadYearMonthDay"));
    }

    private static long TimeToTicks(int hour, int minute, int second)
    {
      if (hour >= 0 && hour < 24 && (minute >= 0 && minute < 60) && (second >= 0 && second < 60))
        return TimeSpan.TimeToTicks(hour, minute, second);
      else
        throw new ArgumentOutOfRangeException((string) null, Environment.GetResourceString("ArgumentOutOfRange_BadHourMinuteSecond"));
    }

    [__DynamicallyInvokable]
    public static int DaysInMonth(int year, int month)
    {
      if (month < 1 || month > 12)
        throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_Month"));
      int[] numArray = DateTime.IsLeapYear(year) ? DateTime.DaysToMonth366 : DateTime.DaysToMonth365;
      return numArray[month] - numArray[month - 1];
    }

    internal static long DoubleDateToTicks(double value)
    {
      if (value >= 2958466.0 || value <= -657435.0)
        throw new ArgumentException(Environment.GetResourceString("Arg_OleAutDateInvalid"));
      long num1 = (long) (value * 86400000.0 + (value >= 0.0 ? 0.5 : -0.5));
      if (num1 < 0L)
      {
        long num2 = num1;
        long num3 = 86400000L;
        long num4 = num2 % num3 * 2L;
        num1 = num2 - num4;
      }
      long num5 = num1 + 59926435200000L;
      if (num5 < 0L || num5 >= 315537897600000L)
        throw new ArgumentException(Environment.GetResourceString("Arg_OleAutDateScale"));
      else
        return num5 * 10000L;
    }

    [SecurityCritical]
    [SuppressUnmanagedCodeSecurity]
    [DllImport("QCall", CharSet = CharSet.Unicode)]
    [return: MarshalAs(UnmanagedType.Bool)]
    internal static bool LegacyParseMode();

    [SecurityCritical]
    [SuppressUnmanagedCodeSecurity]
    [DllImport("QCall", CharSet = CharSet.Unicode)]
    [return: MarshalAs(UnmanagedType.Bool)]
    internal static bool EnableAmPmParseAdjustment();

    [__DynamicallyInvokable]
    public override bool Equals(object value)
    {
      if (value is DateTime)
        return this.InternalTicks == ((DateTime) value).InternalTicks;
      else
        return false;
    }

    [__DynamicallyInvokable]
    public bool Equals(DateTime value)
    {
      return this.InternalTicks == value.InternalTicks;
    }

    [__DynamicallyInvokable]
    public static bool Equals(DateTime t1, DateTime t2)
    {
      return t1.InternalTicks == t2.InternalTicks;
    }

    [__DynamicallyInvokable]
    public static DateTime FromBinary(long dateData)
    {
      if ((dateData & long.MinValue) == 0L)
        return DateTime.FromBinaryRaw(dateData);
      long ticks1 = dateData & 4611686018427387903L;
      if (ticks1 > 4611685154427387904L)
        ticks1 -= 4611686018427387904L;
      bool isAmbiguousDst = false;
      long ticks2;
      if (ticks1 < 0L)
        ticks2 = TimeZoneInfo.GetLocalUtcOffset(DateTime.MinValue, TimeZoneInfoOptions.NoThrowOnInvalidTime).Ticks;
      else if (ticks1 > 3155378975999999999L)
      {
        ticks2 = TimeZoneInfo.GetLocalUtcOffset(DateTime.MaxValue, TimeZoneInfoOptions.NoThrowOnInvalidTime).Ticks;
      }
      else
      {
        DateTime time = new DateTime(ticks1, DateTimeKind.Utc);
        bool flag = false;
        TimeZoneInfo local = TimeZoneInfo.Local;
        // ISSUE: explicit reference operation
        // ISSUE: variable of a reference type
        bool& isDaylightSavings = @flag;
        // ISSUE: explicit reference operation
        // ISSUE: variable of a reference type
        bool& isAmbiguousLocalDst = @isAmbiguousDst;
        ticks2 = TimeZoneInfo.GetUtcOffsetFromUtc(time, local, isDaylightSavings, isAmbiguousLocalDst).Ticks;
      }
      long ticks3 = ticks1 + ticks2;
      if (ticks3 < 0L)
        ticks3 += 864000000000L;
      if (ticks3 < 0L || ticks3 > 3155378975999999999L)
        throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeBadBinaryData"), "dateData");
      else
        return new DateTime(ticks3, DateTimeKind.Local, isAmbiguousDst);
    }

    internal static DateTime FromBinaryRaw(long dateData)
    {
      long num = dateData & 4611686018427387903L;
      if (num < 0L || num > 3155378975999999999L)
        throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeBadBinaryData"), "dateData");
      else
        return new DateTime((ulong) dateData);
    }

    [__DynamicallyInvokable]
    public static DateTime FromFileTime(long fileTime)
    {
      return DateTime.FromFileTimeUtc(fileTime).ToLocalTime();
    }

    [__DynamicallyInvokable]
    public static DateTime FromFileTimeUtc(long fileTime)
    {
      if (fileTime < 0L || fileTime > 2650467743999999999L)
        throw new ArgumentOutOfRangeException("fileTime", Environment.GetResourceString("ArgumentOutOfRange_FileTimeInvalid"));
      else
        return new DateTime(fileTime + 504911232000000000L, DateTimeKind.Utc);
    }

    [__DynamicallyInvokable]
    public static DateTime FromOADate(double d)
    {
      return new DateTime(DateTime.DoubleDateToTicks(d), DateTimeKind.Unspecified);
    }

    [SecurityCritical]
    void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
    {
      if (info == null)
        throw new ArgumentNullException("info");
      info.AddValue("ticks", this.InternalTicks);
      info.AddValue("dateData", this.dateData);
    }

    [__DynamicallyInvokable]
    public bool IsDaylightSavingTime()
    {
      if (this.Kind == DateTimeKind.Utc)
        return false;
      else
        return TimeZoneInfo.Local.IsDaylightSavingTime(this, TimeZoneInfoOptions.NoThrowOnInvalidTime);
    }

    [__DynamicallyInvokable]
    public static DateTime SpecifyKind(DateTime value, DateTimeKind kind)
    {
      return new DateTime(value.InternalTicks, kind);
    }

    [__DynamicallyInvokable]
    public long ToBinary()
    {
      if (this.Kind != DateTimeKind.Local)
        return (long) this.dateData;
      long num = this.Ticks - TimeZoneInfo.GetLocalUtcOffset(this, TimeZoneInfoOptions.NoThrowOnInvalidTime).Ticks;
      if (num < 0L)
        num = 4611686018427387904L + num;
      return num | long.MinValue;
    }

    internal long ToBinaryRaw()
    {
      return (long) this.dateData;
    }

    private int GetDatePart(int part)
    {
      int num1 = (int) (this.InternalTicks / 864000000000L);
      int num2 = num1 / 146097;
      int num3 = num1 - num2 * 146097;
      int num4 = num3 / 36524;
      if (num4 == 4)
        num4 = 3;
      int num5 = num3 - num4 * 36524;
      int num6 = num5 / 1461;
      int num7 = num5 - num6 * 1461;
      int num8 = num7 / 365;
      if (num8 == 4)
        num8 = 3;
      if (part == 0)
        return num2 * 400 + num4 * 100 + num6 * 4 + num8 + 1;
      int num9 = num7 - num8 * 365;
      if (part == 1)
        return num9 + 1;
      int[] numArray = (num8 != 3 ? 0 : (num6 != 24 ? 1 : (num4 == 3 ? 1 : 0))) != 0 ? DateTime.DaysToMonth366 : DateTime.DaysToMonth365;
      int index = num9 >> 6;
      while (num9 >= numArray[index])
        ++index;
      if (part == 2)
        return index;
      else
        return num9 - numArray[index - 1] + 1;
    }

    [__DynamicallyInvokable]
    public override int GetHashCode()
    {
      long internalTicks = this.InternalTicks;
      return (int) internalTicks ^ (int) (internalTicks >> 32);
    }

    internal bool IsAmbiguousDaylightSavingTime()
    {
      return (long) this.InternalKind == -4611686018427387904L;
    }

    [SecurityCritical]
    [MethodImpl(MethodImplOptions.InternalCall)]
    internal static long GetSystemTimeAsFileTime();

    [__DynamicallyInvokable]
    public static bool IsLeapYear(int year)
    {
      if (year < 1 || year > 9999)
        throw new ArgumentOutOfRangeException("year", Environment.GetResourceString("ArgumentOutOfRange_Year"));
      if (year % 4 != 0)
        return false;
      if (year % 100 == 0)
        return year % 400 == 0;
      else
        return true;
    }

    [__DynamicallyInvokable]
    public static DateTime Parse(string s)
    {
      return DateTimeParse.Parse(s, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None);
    }

    [__DynamicallyInvokable]
    public static DateTime Parse(string s, IFormatProvider provider)
    {
      return DateTimeParse.Parse(s, DateTimeFormatInfo.GetInstance(provider), DateTimeStyles.None);
    }

    [__DynamicallyInvokable]
    public static DateTime Parse(string s, IFormatProvider provider, DateTimeStyles styles)
    {
      DateTimeFormatInfo.ValidateStyles(styles, "styles");
      return DateTimeParse.Parse(s, DateTimeFormatInfo.GetInstance(provider), styles);
    }

    [__DynamicallyInvokable]
    public static DateTime ParseExact(string s, string format, IFormatProvider provider)
    {
      return DateTimeParse.ParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), DateTimeStyles.None);
    }

    [__DynamicallyInvokable]
    public static DateTime ParseExact(string s, string format, IFormatProvider provider, DateTimeStyles style)
    {
      DateTimeFormatInfo.ValidateStyles(style, "style");
      return DateTimeParse.ParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), style);
    }

    [__DynamicallyInvokable]
    public static DateTime ParseExact(string s, string[] formats, IFormatProvider provider, DateTimeStyles style)
    {
      DateTimeFormatInfo.ValidateStyles(style, "style");
      return DateTimeParse.ParseExactMultiple(s, formats, DateTimeFormatInfo.GetInstance(provider), style);
    }

    [__DynamicallyInvokable]
    public TimeSpan Subtract(DateTime value)
    {
      return new TimeSpan(this.InternalTicks - value.InternalTicks);
    }

    [__DynamicallyInvokable]
    public DateTime Subtract(TimeSpan value)
    {
      long internalTicks = this.InternalTicks;
      long num = value._ticks;
      if (internalTicks - 0L < num || internalTicks - 3155378975999999999L > num)
        throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic"));
      else
        return new DateTime((ulong) (internalTicks - num) | this.InternalKind);
    }

    private static double TicksToOADate(long value)
    {
      if (value == 0L)
        return 0.0;
      if (value < 864000000000L)
        value += 599264352000000000L;
      if (value < 31241376000000000L)
        throw new OverflowException(Environment.GetResourceString("Arg_OleAutDateInvalid"));
      long num1 = (value - 599264352000000000L) / 10000L;
      if (num1 < 0L)
      {
        long num2 = num1 % 86400000L;
        if (num2 != 0L)
          num1 -= (86400000L + num2) * 2L;
      }
      return (double) num1 / 86400000.0;
    }

    [__DynamicallyInvokable]
    public double ToOADate()
    {
      return DateTime.TicksToOADate(this.InternalTicks);
    }

    [__DynamicallyInvokable]
    public long ToFileTime()
    {
      return this.ToUniversalTime().ToFileTimeUtc();
    }

    [__DynamicallyInvokable]
    public long ToFileTimeUtc()
    {
      long num1 = (((long) this.InternalKind & long.MinValue) != 0L ? this.ToUniversalTime().InternalTicks : this.InternalTicks) - 504911232000000000L;
      long num2 = 0L;
      if (num1 >= num2)
        return num1;
      else
        throw new ArgumentOutOfRangeException((string) null, Environment.GetResourceString("ArgumentOutOfRange_FileTimeInvalid"));
    }

    [__DynamicallyInvokable]
    public DateTime ToLocalTime()
    {
      return this.ToLocalTime(false);
    }

    internal DateTime ToLocalTime(bool throwOnOverflow)
    {
      if (this.Kind == DateTimeKind.Local)
        return this;
      bool isDaylightSavings = false;
      bool isAmbiguousLocalDst = false;
      long ticks = this.Ticks + TimeZoneInfo.GetUtcOffsetFromUtc(this, TimeZoneInfo.Local, out isDaylightSavings, out isAmbiguousLocalDst).Ticks;
      if (ticks > 3155378975999999999L)
      {
        if (throwOnOverflow)
          throw new ArgumentException(Environment.GetResourceString("Arg_ArgumentOutOfRangeException"));
        else
          return new DateTime(3155378975999999999L, DateTimeKind.Local);
      }
      else
      {
        if (ticks >= 0L)
          return new DateTime(ticks, DateTimeKind.Local, isAmbiguousLocalDst);
        if (throwOnOverflow)
          throw new ArgumentException(Environment.GetResourceString("Arg_ArgumentOutOfRangeException"));
        else
          return new DateTime(0L, DateTimeKind.Local);
      }
    }

    public string ToLongDateString()
    {
      return DateTimeFormat.Format(this, "D", DateTimeFormatInfo.CurrentInfo);
    }

    public string ToLongTimeString()
    {
      return DateTimeFormat.Format(this, "T", DateTimeFormatInfo.CurrentInfo);
    }

    public string ToShortDateString()
    {
      return DateTimeFormat.Format(this, "d", DateTimeFormatInfo.CurrentInfo);
    }

    public string ToShortTimeString()
    {
      return DateTimeFormat.Format(this, "t", DateTimeFormatInfo.CurrentInfo);
    }

    [__DynamicallyInvokable]
    public override string ToString()
    {
      return DateTimeFormat.Format(this, (string) null, DateTimeFormatInfo.CurrentInfo);
    }

    [__DynamicallyInvokable]
    public string ToString(string format)
    {
      return DateTimeFormat.Format(this, format, DateTimeFormatInfo.CurrentInfo);
    }

    [__DynamicallyInvokable]
    public string ToString(IFormatProvider provider)
    {
      return DateTimeFormat.Format(this, (string) null, DateTimeFormatInfo.GetInstance(provider));
    }

    [__DynamicallyInvokable]
    public string ToString(string format, IFormatProvider provider)
    {
      return DateTimeFormat.Format(this, format, DateTimeFormatInfo.GetInstance(provider));
    }

    [__DynamicallyInvokable]
    public DateTime ToUniversalTime()
    {
      return TimeZoneInfo.ConvertTimeToUtc(this, TimeZoneInfoOptions.NoThrowOnInvalidTime);
    }

    [__DynamicallyInvokable]
    public static bool TryParse(string s, out DateTime result)
    {
      return DateTimeParse.TryParse(s, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None, out result);
    }

    [__DynamicallyInvokable]
    public static bool TryParse(string s, IFormatProvider provider, DateTimeStyles styles, out DateTime result)
    {
      DateTimeFormatInfo.ValidateStyles(styles, "styles");
      return DateTimeParse.TryParse(s, DateTimeFormatInfo.GetInstance(provider), styles, out result);
    }

    [__DynamicallyInvokable]
    public static bool TryParseExact(string s, string format, IFormatProvider provider, DateTimeStyles style, out DateTime result)
    {
      DateTimeFormatInfo.ValidateStyles(style, "style");
      return DateTimeParse.TryParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), style, out result);
    }

    [__DynamicallyInvokable]
    public static bool TryParseExact(string s, string[] formats, IFormatProvider provider, DateTimeStyles style, out DateTime result)
    {
      DateTimeFormatInfo.ValidateStyles(style, "style");
      return DateTimeParse.TryParseExactMultiple(s, formats, DateTimeFormatInfo.GetInstance(provider), style, out result);
    }

    [__DynamicallyInvokable]
    public string[] GetDateTimeFormats()
    {
      return this.GetDateTimeFormats((IFormatProvider) CultureInfo.CurrentCulture);
    }

    [__DynamicallyInvokable]
    public string[] GetDateTimeFormats(IFormatProvider provider)
    {
      return DateTimeFormat.GetAllDateTimes(this, DateTimeFormatInfo.GetInstance(provider));
    }

    [__DynamicallyInvokable]
    public string[] GetDateTimeFormats(char format)
    {
      return this.GetDateTimeFormats(format, (IFormatProvider) CultureInfo.CurrentCulture);
    }

    [__DynamicallyInvokable]
    public string[] GetDateTimeFormats(char format, IFormatProvider provider)
    {
      return DateTimeFormat.GetAllDateTimes(this, format, DateTimeFormatInfo.GetInstance(provider));
    }

    public TypeCode GetTypeCode()
    {
      return TypeCode.DateTime;
    }

    [__DynamicallyInvokable]
    bool IConvertible.ToBoolean(IFormatProvider provider)
    {
      string key = "InvalidCast_FromTo";
      object[] objArray = new object[2];
      int index1 = 0;
      string str1 = "DateTime";
      objArray[index1] = (object) str1;
      int index2 = 1;
      string str2 = "Boolean";
      objArray[index2] = (object) str2;
      throw new InvalidCastException(Environment.GetResourceString(key, objArray));
    }

    [__DynamicallyInvokable]
    char IConvertible.ToChar(IFormatProvider provider)
    {
      string key = "InvalidCast_FromTo";
      object[] objArray = new object[2];
      int index1 = 0;
      string str1 = "DateTime";
      objArray[index1] = (object) str1;
      int index2 = 1;
      string str2 = "Char";
      objArray[index2] = (object) str2;
      throw new InvalidCastException(Environment.GetResourceString(key, objArray));
    }

    [__DynamicallyInvokable]
    sbyte IConvertible.ToSByte(IFormatProvider provider)
    {
      string key = "InvalidCast_FromTo";
      object[] objArray = new object[2];
      int index1 = 0;
      string str1 = "DateTime";
      objArray[index1] = (object) str1;
      int index2 = 1;
      string str2 = "SByte";
      objArray[index2] = (object) str2;
      throw new InvalidCastException(Environment.GetResourceString(key, objArray));
    }

    [__DynamicallyInvokable]
    byte IConvertible.ToByte(IFormatProvider provider)
    {
      string key = "InvalidCast_FromTo";
      object[] objArray = new object[2];
      int index1 = 0;
      string str1 = "DateTime";
      objArray[index1] = (object) str1;
      int index2 = 1;
      string str2 = "Byte";
      objArray[index2] = (object) str2;
      throw new InvalidCastException(Environment.GetResourceString(key, objArray));
    }

    [__DynamicallyInvokable]
    short IConvertible.ToInt16(IFormatProvider provider)
    {
      string key = "InvalidCast_FromTo";
      object[] objArray = new object[2];
      int index1 = 0;
      string str1 = "DateTime";
      objArray[index1] = (object) str1;
      int index2 = 1;
      string str2 = "Int16";
      objArray[index2] = (object) str2;
      throw new InvalidCastException(Environment.GetResourceString(key, objArray));
    }

    [__DynamicallyInvokable]
    ushort IConvertible.ToUInt16(IFormatProvider provider)
    {
      string key = "InvalidCast_FromTo";
      object[] objArray = new object[2];
      int index1 = 0;
      string str1 = "DateTime";
      objArray[index1] = (object) str1;
      int index2 = 1;
      string str2 = "UInt16";
      objArray[index2] = (object) str2;
      throw new InvalidCastException(Environment.GetResourceString(key, objArray));
    }

    [__DynamicallyInvokable]
    int IConvertible.ToInt32(IFormatProvider provider)
    {
      string key = "InvalidCast_FromTo";
      object[] objArray = new object[2];
      int index1 = 0;
      string str1 = "DateTime";
      objArray[index1] = (object) str1;
      int index2 = 1;
      string str2 = "Int32";
      objArray[index2] = (object) str2;
      throw new InvalidCastException(Environment.GetResourceString(key, objArray));
    }

    [__DynamicallyInvokable]
    uint IConvertible.ToUInt32(IFormatProvider provider)
    {
      string key = "InvalidCast_FromTo";
      object[] objArray = new object[2];
      int index1 = 0;
      string str1 = "DateTime";
      objArray[index1] = (object) str1;
      int index2 = 1;
      string str2 = "UInt32";
      objArray[index2] = (object) str2;
      throw new InvalidCastException(Environment.GetResourceString(key, objArray));
    }

    [__DynamicallyInvokable]
    long IConvertible.ToInt64(IFormatProvider provider)
    {
      string key = "InvalidCast_FromTo";
      object[] objArray = new object[2];
      int index1 = 0;
      string str1 = "DateTime";
      objArray[index1] = (object) str1;
      int index2 = 1;
      string str2 = "Int64";
      objArray[index2] = (object) str2;
      throw new InvalidCastException(Environment.GetResourceString(key, objArray));
    }

    [__DynamicallyInvokable]
    ulong IConvertible.ToUInt64(IFormatProvider provider)
    {
      string key = "InvalidCast_FromTo";
      object[] objArray = new object[2];
      int index1 = 0;
      string str1 = "DateTime";
      objArray[index1] = (object) str1;
      int index2 = 1;
      string str2 = "UInt64";
      objArray[index2] = (object) str2;
      throw new InvalidCastException(Environment.GetResourceString(key, objArray));
    }

    [__DynamicallyInvokable]
    float IConvertible.ToSingle(IFormatProvider provider)
    {
      string key = "InvalidCast_FromTo";
      object[] objArray = new object[2];
      int index1 = 0;
      string str1 = "DateTime";
      objArray[index1] = (object) str1;
      int index2 = 1;
      string str2 = "Single";
      objArray[index2] = (object) str2;
      throw new InvalidCastException(Environment.GetResourceString(key, objArray));
    }

    [__DynamicallyInvokable]
    double IConvertible.ToDouble(IFormatProvider provider)
    {
      string key = "InvalidCast_FromTo";
      object[] objArray = new object[2];
      int index1 = 0;
      string str1 = "DateTime";
      objArray[index1] = (object) str1;
      int index2 = 1;
      string str2 = "Double";
      objArray[index2] = (object) str2;
      throw new InvalidCastException(Environment.GetResourceString(key, objArray));
    }

    [__DynamicallyInvokable]
    Decimal IConvertible.ToDecimal(IFormatProvider provider)
    {
      string key = "InvalidCast_FromTo";
      object[] objArray = new object[2];
      int index1 = 0;
      string str1 = "DateTime";
      objArray[index1] = (object) str1;
      int index2 = 1;
      string str2 = "Decimal";
      objArray[index2] = (object) str2;
      throw new InvalidCastException(Environment.GetResourceString(key, objArray));
    }

    [__DynamicallyInvokable]
    DateTime IConvertible.ToDateTime(IFormatProvider provider)
    {
      return this;
    }

    [__DynamicallyInvokable]
    object IConvertible.ToType(Type type, IFormatProvider provider)
    {
      return Convert.DefaultToType((IConvertible) this, type, provider);
    }

    internal static bool TryCreate(int year, int month, int day, int hour, int minute, int second, int millisecond, out DateTime result)
    {
      result = DateTime.MinValue;
      if (year < 1 || year > 9999 || (month < 1 || month > 12))
        return false;
      int[] numArray = DateTime.IsLeapYear(year) ? DateTime.DaysToMonth366 : DateTime.DaysToMonth365;
      if (day < 1 || day > numArray[month] - numArray[month - 1] || (hour < 0 || hour >= 24) || (minute < 0 || minute >= 60 || (second < 0 || second >= 60)) || (millisecond < 0 || millisecond >= 1000))
        return false;
      long ticks = DateTime.DateToTicks(year, month, day) + DateTime.TimeToTicks(hour, minute, second) + (long) millisecond * 10000L;
      if (ticks < 0L || ticks > 3155378975999999999L)
        return false;
      result = new DateTime(ticks, DateTimeKind.Unspecified);
      return true;
    }
  }
}