C# Unix转换本地时间, Unix时间戳转换DateTime
using System;
namespace ConsoleApp13
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(GetLocalTime("1596865604"));
Console.Read();
}
/// <summary>
/// Unix转换本地时间
/// </summary>
/// <param name="timeStamp">Unix时间戳</param>
/// <returns></returns>
public static DateTime GetLocalTime(string timeStamp)
{
long time = long.Parse(timeStamp + "0000000");
DateTime start = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0, 0));
TimeSpan toCurrent = new TimeSpan(time);
return start.Add(toCurrent);
}
}
}