Created
April 23, 2019 17:35
-
-
Save codenamejason/6c5bf1f3697f24857765039730131d4c to your computer and use it in GitHub Desktop.
Convert Unix Epoch time to DateTime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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