Added Utility.Epoch

This commit is contained in:
Garry Newman 2016-11-11 10:44:02 +00:00
parent b8e6614f67
commit 6a5603a121

View File

@ -14,5 +14,30 @@ namespace Facepunch.Steamworks
( ( x & 0x00ff0000 ) >> 8 ) +
( ( x & 0xff000000 ) >> 24 );
}
static internal class Epoch
{
private static readonly DateTime epoch = new DateTime( 1970, 1, 1, 0, 0, 0, DateTimeKind.Utc );
/// <summary>
/// Returns the current Unix Epoch
/// </summary>
public static int Current
{
get
{
return (int)( DateTime.UtcNow.Subtract( epoch ).TotalSeconds );
}
}
/// <summary>
/// Convert an epoch to a datetime
/// </summary>
public static DateTime ToDateTime( decimal unixTime )
{
return epoch.AddSeconds( (long)unixTime );
}
}
}
}