美文网首页
C# 获取时间戳

C# 获取时间戳

作者: Rinaloving | 来源:发表于2020-12-02 10:35 被阅读0次

获取时间戳

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;
 
}

相关文章

网友评论

      本文标题:C# 获取时间戳

      本文链接:https://www.haomeiwen.com/subject/eryywktx.html