UnixTimestamp(unix timestamp) C# converter
UnixTimestamp(unix timestamp) C# converter
資料來源: https://stackoverflow.com/questions/249760/how-can-i-convert-a-unix-timestamp-to-datetime-and-vice-versa
public static DateTime UnixTimeStampToDateTime( double unixTimeStamp ) { // Unix timestamp is seconds past epoch DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); dateTime = dateTime.AddSeconds( unixTimeStamp ).ToLocalTime(); return dateTime; } public static DateTime JavaTimeStampToDateTime( double javaTimeStamp ) { // Java timestamp is milliseconds past epoch DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); dateTime = dateTime.AddMilliseconds( javaTimeStamp ).ToLocalTime(); return dateTime; }
One thought on “UnixTimestamp(unix timestamp) C# converter”
https://ourcodeworld.com/articles/read/865/how-to-convert-an-unixtime-to-datetime-class-and-viceversa-in-c-sharp
public long DateTimeToUnixTimeStamp(DateTime MyDateTime)
{
TimeSpan timeSpan = MyDateTime - new DateTime(1970, 1, 1, 0, 0, 0);
return (long)timeSpan.TotalSeconds;
}