C# 获取时间戳

2020-12-02  本文已影响0人  Rinaloving

获取时间戳

TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
string curTime = Convert.ToInt64(ts.TotalMilliseconds).ToString();  // 1606876382433

时间戳转为C#格式时间

// 时间戳转为C#格式时间
private DateTime StampToDateTime(string time)
{
 
        time = time.Substring(0, 10);
        double timestamp = Convert.ToInt64(time);
        System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
        dateTime = dateTime.AddSeconds(timestamp).ToLocalTime();       
        return dateTime;
 
}

上一篇 下一篇

猜你喜欢

热点阅读