added DateTimeToUnixTimestamp helper

This commit is contained in:
Serraniel 2017-05-20 10:17:59 +02:00
parent 1116e85cd7
commit 01b4c28054

View file

@ -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));
}
/// <summary>
/// Converts a <see cref="DateTime"/> into an Unix timestamp.
/// </summary>
/// <param name="date"><see cref="DateTime"/> to convert into Unix timestamp.</param>
/// <returns>Converted Unix timestamp</returns>
public static double DateTimeToUnixTimeStamp(DateTime date)
{
return date.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
}
}
}