UnixTimestamp(unix timestamp) C# converter

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

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *