Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save codenamejason/6c5bf1f3697f24857765039730131d4c to your computer and use it in GitHub Desktop.
Save codenamejason/6c5bf1f3697f24857765039730131d4c to your computer and use it in GitHub Desktop.
Convert Unix Epoch time to DateTime
public static DateTime UnixTimestampToDateTime(string unixTimestamp)
{
var time = Convert.ToDouble(unixTimestamp);
DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
dtDateTime = dtDateTime.AddSeconds(time).ToLocalTime();
return dtDateTime;
}
public static string UnixTimeStampToString(string unixTimeStamp)
{
var time = Convert.ToDouble(unixTimeStamp);
DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
dtDateTime = dtDateTime.AddSeconds(time).ToLocalTime();
CultureInfo culture = new CultureInfo("en-US");
return dtDateTime.ToString("d", DateTimeFormatInfo.InvariantInfo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment