C# 生成时间戳

来源:互联网 发布:淘宝欧莱雅官方网 编辑:程序博客网 时间:2024/05/16 19:37

今天在使用C#将日期转换成时间戳的时候,出现了转换过去的时间一直是8:00,后来发现是未进行时区转换。

TimeSpan ts = Convert.ToDateTime(DateTimeStr) -  TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1,0,0,0));int seconds = (int)ts.TotalSeconds;
0 0