优化更新代码,添加界面功能并整合
This commit is contained in:
37
WPFluent/Extensions/DateTimeExtensions.cs
Normal file
37
WPFluent/Extensions/DateTimeExtensions.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
|
||||
|
||||
namespace WPFluent.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// A collection of several extensions to the <see cref="DateTime"/> class.
|
||||
/// </summary>
|
||||
public static class DateTimeExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public static long GetMicroTimestamp(this DateTime dateTime)
|
||||
{
|
||||
// Should be 10^-6
|
||||
return dateTime.Subtract(new DateTime(1970, 1, 1)).Ticks / (TimeSpan.TicksPerMillisecond / 1000);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public static long GetMillisTimestamp(this DateTime dateTime)
|
||||
{
|
||||
// Should be 10^-3
|
||||
return (long)dateTime.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public static long GetTimestamp(this DateTime dateTime)
|
||||
{ return (long)dateTime.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; }
|
||||
}
|
||||
Reference in New Issue
Block a user