Datetime from an int representing a unix epoch time - CSharp System

CSharp examples for System:DateTime Unix

Description

Datetime from an int representing a unix epoch time

Demo Code


using System;//from  ww  w .  ja va2 s. c  om

public class Main{
        /// <summary>
        /// Datetime from an int representing a unix epoch time
        /// </summary>
        /// <param name="msSinceEpoch"></param>
        /// <returns></returns>
        public static DateTimeOffset EpochMillisecondsToDateTime(this long msSinceEpoch)
        {
            var date = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
            return date.AddMilliseconds(msSinceEpoch);
        }
}

Related Tutorials