Last Updated: February 18, 2017
·
44.46K
· tylerfowler

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);

1 Response
Add your response

Set the datetime kind!

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

over 1 year ago ·