namespace WPFluent.Extensions; /// /// A collection of several extensions to the class. /// public static class DateTimeExtensions { /// /// Gets the number of microseconds that have elapsed since the Unix epoch, excluding leap seconds. The Unix epoch /// is 00:00:00 UTC on 1 January 1970. /// public static long GetMicroTimestamp(this DateTime dateTime) { // Should be 10^-6 return dateTime.Subtract(new DateTime(1970, 1, 1)).Ticks / (TimeSpan.TicksPerMillisecond / 1000); } /// /// Gets the number of milliseconds that have elapsed since the Unix epoch, excluding leap seconds. The Unix epoch /// is 00:00:00 UTC on 1 January 1970. /// public static long GetMillisTimestamp(this DateTime dateTime) { // Should be 10^-3 return (long)dateTime.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds; } /// /// Gets the number of seconds that have elapsed since the Unix epoch, excluding leap seconds. The Unix epoch is /// 00:00:00 UTC on 1 January 1970. /// public static long GetTimestamp(this DateTime dateTime) { return (long)dateTime.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; } }