unix timestamp to hours minutes seconds c# code example

Example 1: c# convert Unix time in seconds to datetime

public static DateTime UnixTimeStampToDateTime( double unixTimeStamp )
{
    // Unix timestamp is seconds past epoch
    System.DateTime dtDateTime = new DateTime(1970,1,1,0,0,0,0,System.DateTimeKind.Utc);
    dtDateTime = dtDateTime.AddSeconds( unixTimeStamp ).ToLocalTime();
    return dtDateTime;
}

Example 2: unix time c#

Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

Example 3: milliseconds to seconds C#

string l_Time = string.Format("{0} s", TimeSpan.FromMilliseconds(154820).TotalSeconds.ToString());
//154.82 s
//https://www.tutorialspoint.com/compile_csharp_online.php