feat: Added util extension method for converting a DateTime to a Unix timestamp

This commit is contained in:
Laura Gomez
2019-07-12 13:57:52 -04:00
parent 7add461a1a
commit 6e056c9dcc

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using ICD.Common.Properties;
namespace ICD.Common.Utils.Extensions namespace ICD.Common.Utils.Extensions
{ {
@@ -83,5 +84,13 @@ namespace ICD.Common.Utils.Extensions
{ {
return extends.StartOfDay() + new TimeSpan(24, 0, 0); return extends.StartOfDay() + new TimeSpan(24, 0, 0);
} }
[PublicAPI]
public static double ToUnixTimestamp(this DateTime extends)
{
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
TimeSpan diff = extends.ToUniversalTime() - origin;
return Math.Floor(diff.TotalSeconds);
}
} }
} }