From 01b4c28054410e2ce6e2f4653907da55b8da936e Mon Sep 17 00:00:00 2001 From: Serraniel Date: Sat, 20 May 2017 10:17:59 +0200 Subject: [PATCH] added DateTimeToUnixTimestamp helper --- SweetLib/Utils/SweetUtils.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/SweetLib/Utils/SweetUtils.cs b/SweetLib/Utils/SweetUtils.cs index 57e2a2a..53e6b3a 100644 --- a/SweetLib/Utils/SweetUtils.cs +++ b/SweetLib/Utils/SweetUtils.cs @@ -34,10 +34,20 @@ namespace SweetLib.Utils { var invalidChars = System.IO.Path.GetInvalidFileNameChars(); - if(invalidChars.Contains(replaceChar)) + if (invalidChars.Contains(replaceChar)) throw new IOException($"Replace character {replaceChar} is an invalid file name character."); return invalidChars.Aggregate(fileName, (current, c) => current.Replace(c, replaceChar)); } + + /// + /// Converts a into an Unix timestamp. + /// + /// to convert into Unix timestamp. + /// Converted Unix timestamp + public static double DateTimeToUnixTimeStamp(DateTime date) + { + return date.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; + } } }