How to transform a UNIX timestamp into DateTime?

1

I have a date field in the format UNIX timestamp , and I need to transform this field to a DateTime of C #. How to proceed?

  

Example input: 1514959643539

     

Output desired: DateTime with correct date / time information ( 03/01/2018 06:07:23 )

    
asked by anonymous 02.03.2018 / 10:35

1 answer

1

The System.DateTimeOffset class has methods suitable for manipulating UNIX timestamps in a C # development environment. We can do the desired transformation with the code below (the code was created to run in LINQPad , the Dump() function (which is specific to this application) simply prints whatever is in the variable as graphically as possible:

void Main()
{
    var dateTime = DateTimeOffset.FromUnixTimeMilliseconds(1514959643539).UtcDateTime;

    dateTime.Dump(); // 03/01/2018 06:07:23
}

02.03.2018 / 10:35