From 6a5603a12132e3b2c3b8d12ab6c05310f105cdea Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Fri, 11 Nov 2016 10:44:02 +0000 Subject: [PATCH] Added Utility.Epoch --- Facepunch.Steamworks/Utility.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Facepunch.Steamworks/Utility.cs b/Facepunch.Steamworks/Utility.cs index 6546416..0e4593b 100644 --- a/Facepunch.Steamworks/Utility.cs +++ b/Facepunch.Steamworks/Utility.cs @@ -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 ); + + /// + /// Returns the current Unix Epoch + /// + public static int Current + { + get + { + return (int)( DateTime.UtcNow.Subtract( epoch ).TotalSeconds ); + } + } + + /// + /// Convert an epoch to a datetime + /// + public static DateTime ToDateTime( decimal unixTime ) + { + return epoch.AddSeconds( (long)unixTime ); + } + + } } }