corrade-vassal
/wasSharp/Time.cs |
@@ -18,6 +18,28 @@ |
{ |
public delegate void TimerCallback(object state); |
|
/// <summary> |
/// Convert an Unix timestamp to a DateTime structure. |
/// </summary> |
/// <param name="unixTimestamp">the Unix timestamp to convert</param> |
/// <returns>the DateTime structure</returns> |
/// <remarks>the function assumes UTC time</remarks> |
public static DateTime UnixTimestampToDateTime(uint unixTimestamp) |
{ |
return new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(unixTimestamp).ToUniversalTime(); |
} |
|
/// <summary> |
/// Convert a DateTime structure to a Unix timestamp. |
/// </summary> |
/// <param name="dateTime">the DateTime structure to convert</param> |
/// <returns>the Unix timestamp</returns> |
/// <remarks>the function assumes UTC time</remarks> |
public static uint DateTimeToUnixTimestamp(DateTime dateTime) |
{ |
return (uint) (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds; |
} |
|
public sealed class Timer : IDisposable |
{ |
private static readonly Task CompletedTask = Task.FromResult(false); |