e8rzuq
Last Updated: February 18, 2017
·
9.557K
· tylerfowler
878a87ce30eec604f62b772289b9692e

How to convert a UNIX Timestamp to a .NET System.DateTime object

// Example of a UNIX timestamp for 11-29-2013 4:58:30
double timestamp = 1385701110;

// Format our new DateTime object to start at the UNIX Epoch
System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);

// Add the timestamp (number of seconds since the Epoch) to be converted
dateTime = dateTime.AddSeconds(timestamp);
Say Thanks
Respond

1 Response
Add your response

28620
Profile fb

Set the datetime kind!

new System.DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

5 months ago ·