c# – How to convert a value in UNIX Timestamp type to DateTime?

Question:

How to convert a value of type UNIX timestamp (seconds since 1970) , example 1396148400 , to a DateTime ?

Answer:

One way to handle unix timestamp;

string start = "1396148900"; // o teu exemplo;
 // Criar equivalente Datetime > UNIX Epoch. (seconds since 1970)
 DateTime dtIni = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);

 // adicionar o nº de segundos  UNIX timestamp para comversão;
 dtIni = dateTime.AddSeconds(double.Parse(start));
Scroll to Top