public static void Main()
var a = Convert.ToDouble("1601510400000");
var b = "18446681938112751616";
var c = Convert.ToDouble(b);
var d = "0001-01-01T00:00:00";
var e = new Date(Convert.ToDateTime(d));
var f = ((UInt64)((Date)e).ToDateTime.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds).ToString();
Console.WriteLine(new DateTime(1970, 1, 1).AddMilliseconds(a));
Console.WriteLine(new DateTime(1970, 1, 1));
Console.WriteLine(DateTime.MinValue);
public class Date : IComparable<Date>
public Date(DateTime date)
public Date(int year, int month, int day)
Month = DateTime.MinValue.Month;
Year = DateTime.MinValue.Year;
Day = DateTime.MinValue.Day;
public int Month { get; set; }
public int Year { get; set; }
public int Day { get; set; }
get { return ToDateTime.ToString("yyyy-MM-dd"); }
public int CompareTo(Date other)
return IsAfter(other) ? 1 : other.IsAfter(this) ? -1 : 0;
public override string ToString()
return Month + "/" + Day + "/" + Year;
public DateTime ToDateTime
var dateTime = default(DateTime);
dateTime = new DateTime(Year, Month, Day);
return (Year == DateTime.MinValue.Year && Month == DateTime.MinValue.Month && Day == DateTime.MinValue.Day)
|| (Year == DateTime.MaxValue.Year && Month == DateTime.MaxValue.Month && Day == DateTime.MaxValue.Day);
protected bool Equals(Date other)
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return other.Year == Year && other.Month == Month && other.Day == Day;
public override bool Equals(object obj)
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj.GetType() == GetType() && Equals((Date)obj);
public bool IsAfter(Date other)
public bool IsOnOrAfter(Date other)
public bool IsBefore(Date other)
public bool IsOnOrBefore(Date other)
public int YearSpan(Date date)
var isAfter = date > this;
var d1 = isAfter ? date : this;
var d2 = isAfter ? this : date;
var value = d1.Year - d2.Year;
if (d1.Month < d2.Month || (d1.Month == d2.Month && d1.Day < d2.Day))
public static bool operator !=(Date d1, Date d2)
return ReferenceEquals(d1, null) ? !ReferenceEquals(d2, null) : !d1.Equals(d2);
public static bool operator <(Date d1, Date d2)
return d1.ToDateTime < d2.ToDateTime;
public static bool operator <=(Date d1, Date d2)
return d1.ToDateTime <= d2.ToDateTime;
public static bool operator ==(Date d1, Date d2)
return ReferenceEquals(d1, null) ? ReferenceEquals(d2, null) : d1.Equals(d2);
public static bool operator >(Date d1, Date d2)
return d1.ToDateTime > d2.ToDateTime;
public static bool operator >=(Date d1, Date d2)
return d1.ToDateTime >= d2.ToDateTime;
public override int GetHashCode()
var result = Month.GetHashCode() * Day.GetHashCode();
result = (result * 397) ^ (Year.GetHashCode());