C#编程之日期转秒,秒转日期代码,将datetime类型的数据转换成秒显示,比如 2011-09-21 12:23:23 转成double类型 235566445000
查找了相关的文档后得出以下快捷方法,供以下参考,使用
//一种方法
TimeSpan ts = new TimeSpan(DateTime.Now.Ticks);
ts.TotalSeconds;//返回自0001-01-01 00:00:00 以来的秒数
//二种方法
DateTime tsBegin = new DateTime(DateTime.MinValue.Ticks);
DateTime tsEnd = new DateTime(Convert.ToDateTime(end).Ticks);
Double second = (tsEnd - tsBegin).TotalSeconds;//求出两个时间相差的总秒数
//将相差的秒数,还原成日期
Console.WriteLine(tsBegin.AddSeconds(second));
Console.Read();
转自原文:http://www.wowohi.com/article/html/sort045/sort074/Cs/989.html
转载于:https://blog.51cto.com/zyfnet/947675