public class UnixTime { public static DateTime UnixBegun = new DateTime(1970, 1, 1, 0, 0, 0); private Int64 Second; public UnixTime(Int64 second) { Second = second; } public static Int64 GetUnixTime() { return new UnixTime((Int64)(System.DateTime.UtcNow - UnixBegun).TotalSeconds); } public static UnixTime GetUnixTimeFromDateTime(System.DateTime datetime) { return new UnixTime((Int64)(datetime - UnixBegun).TotalSeconds); } public static implicit operator Int64(UnixTime UT) { return UT.Second; } public static implicit operator UnixTime(Int64 d) { return new UnixTime(d); } public static Int64 operator -(UnixTime UT1, UnixTime UT2) { return new UnixTime(UT1.Second - UT2.Second); } public static Int64 operator +(UnixTime UT1, UnixTime UT2) { return new UnixTime(UT1.Second + UT2.Second); } public static bool operator ==(UnixTime UT1, UnixTime UT2) { return UT1.Second == UT2.Second ? true : false; } public static bool operator !=(UnixTime UT1, UnixTime UT2) { return UT1.Second != UT2.Second ? true : false; } public override string ToString() { return Second.ToString(); } }