/////////////////////////////////////////////////////////////////////////// // Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3 // // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // // rights of fair usage, the disclaimer and warranty conditions. // /////////////////////////////////////////////////////////////////////////// using System; namespace wasSharp.Timers.Utilities { public static class TimeExtensions { /// /// Convert an Unix timestamp to a DateTime structure. /// /// the Unix timestamp to convert /// the DateTime structure /// the function assumes UTC time public static DateTime UnixTimestampToDateTime(this uint unixTimestamp) { return new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(unixTimestamp).ToUniversalTime(); } /// /// Convert a DateTime structure to a Unix timestamp. /// /// the DateTime structure to convert /// the Unix timestamp /// the function assumes UTC time public static uint DateTimeToUnixTimestamp(this DateTime dateTime) { return (uint)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds; } } }