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);
Written by Tyler Fowler
Related protips
1 Response
Set the datetime kind!
new System.DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#.net
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#