/// <summary> /// Converts a unix datetime to C# DateTime /// </summary> /// <param name="unixTimeStamp"></param> /// <returns></returns> public static DateTime UnixTimeStampToDateTime(double unixTimeStamp) { // Unix timestamp is seconds past epoch System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToUniversalTime(); return dtDateTime; } /// <summary> /// Converts C# DateTime to unix datetime /// </summary> /// <param name="dateTime"></param> /// <returns></returns> public static double DateTimeToUnixTimestamp(DateTime dateTime) { return (dateTime.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).ToUniversalTime()).TotalSeconds; }
From here.
0 comments:
Post a Comment