C# 时间戳转换

System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc));
// Javascript时间戳
long timeStamp = (long)(DateTime.Now - startTime).TotalMilliseconds;
DateTime dt = startTime.AddMilliseconds(timeStamp);
// Unix时间戳
long timeStamp = (long)(DateTime.Now - startTime).Seconds;
DateTime dt = startTime.AddSeconds(timeStamp);

 

posted @ 2018-11-30 13:27  lovewl  阅读(177)  评论(0编辑  收藏  举报