Convert Unix Time To Date Time - CSharp System

CSharp examples for System:DateTime Convert

Description

Convert Unix Time To Date Time

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//  w w  w .  j av  a 2  s .  com

public class Main{
        //adapted from- http://stackoverflow.com/questions/249760/how-to-convert-a-unix-timestamp-to-datetime-and-vice-versa
        public static DateTime ConvertUnixTimeToDateTime(double unix)
        {
            DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
            dt = dt.AddSeconds(unix).ToLocalTime();
            return dt;
        }
}

Related Tutorials