added UnixTimestampToDatetime
This commit is contained in:
parent
01b4c28054
commit
817cc3a822
|
@ -44,10 +44,20 @@ namespace SweetLib.Utils
|
||||||
/// Converts a <see cref="DateTime"/> into an Unix timestamp.
|
/// Converts a <see cref="DateTime"/> into an Unix timestamp.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="date"><see cref="DateTime"/> to convert into Unix timestamp.</param>
|
/// <param name="date"><see cref="DateTime"/> to convert into Unix timestamp.</param>
|
||||||
/// <returns>Converted Unix timestamp</returns>
|
/// <returns>Converted Unix timestamp.</returns>
|
||||||
public static double DateTimeToUnixTimeStamp(DateTime date)
|
public static double DateTimeToUnixTimeStamp(DateTime date)
|
||||||
{
|
{
|
||||||
return date.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
return date.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts an Unix timestamp into a <see cref="DateTime"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="timestamp">Unix timestamp to convert.</param>
|
||||||
|
/// <returns>Converted <see cref="DateTime"/>.</returns>
|
||||||
|
public static DateTime UnixTimestampToDateTime(double timestamp)
|
||||||
|
{
|
||||||
|
return new DateTime(1970, 1, 1).AddMilliseconds(timestamp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue