Pchp.Library.DateTimeUtils.UtcToUnixTimeStamp C# (CSharp) Method

UtcToUnixTimeStamp() static private method

Converts System_DateTime representing UTC time to UNIX timestamp.
static private UtcToUnixTimeStamp ( System.DateTime dt ) : int
dt System.DateTime Time.
return int
        internal static int UtcToUnixTimeStamp(System_DateTime dt)
        {
            double seconds = (dt - UtcStartOfUnixEpoch).TotalSeconds;

            if (seconds < Int32.MinValue)
                return Int32.MinValue;
            if (seconds > Int32.MaxValue)
                return Int32.MaxValue;

            return (int)seconds;
        }

Usage Example

Ejemplo n.º 1
0
        static int GetSwatchBeat(System_DateTime utc)
        {
            int seconds = DateTimeUtils.UtcToUnixTimeStamp(utc);
            int beat    = (int)(((seconds - (seconds - ((seconds % 86400) + 3600))) * 10) / 864) % 1000;

            return((beat < 0) ? beat + 1000 : beat);
        }
All Usage Examples Of Pchp.Library.DateTimeUtils::UtcToUnixTimeStamp