Converts a Unix time to DateTime - CSharp System

CSharp examples for System:DateTime Unix

Description

Converts a Unix time to DateTime

Demo Code


using System;/*from  w  w w  .  j  a va2s . c o m*/

public class Main{
        /// <summary>
        /// Converts a Unix time to DateTime
        /// </summary>
        /// <param name="unixTimeStamp"></param>
        /// <returns></returns>
        public static DateTime ToDateTime(this long unixTimeStamp)
        {
            DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            return origin.AddSeconds(unixTimeStamp);
        }
}

Related Tutorials