How to convert a value in UNIX type Timestamp to Datetime?

Asked

Viewed 237 times

6

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

1 answer

5


A way to treat 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));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.