C# 时间函数相减

1:第一种方式:
string firsttime = "";

string secondtime = "";

DateTime firstDateTemp = DateTime.ParseExact(firsttime, "yyyyMMddHHmmss", new System.Globalization.CultureInfo("zh-CN", true));

DateTime secondDateTemp = DateTime.ParseExact(secondtime, "yyyyMMddHHmmss", new System.Globalization.CultureInfo("zh-CN", true));            

TimeSpan span = firstDateTemp.Subtract(secondDateTemp);

然后,如果相差一天,那么span.Days=,如果是一年,那么span.Days=<br>             span.Hours, span.Minutes就不举例了

2:第二种方式:

DateTime onetime = DateTime.Parse("2014-2-26 05:32:22");

    DateTime twotime = DateTime.Parse("2014-2-26 05:31:22");

    TimeSpan span = onetime .Subtract(twotime );
上一篇:循环语句--do...while


下一篇:Unity GeometryShader(从一个线框渲染的例子开始)