日期:2014-05-20  浏览次数:20754 次

时间差的问题

                                System.TimeSpan   ts   =   DateTime.Parse( "2007-01-12   17:12:13.000 ")   -   DateTime.Parse(ThisTime);
                         
                                int   ts_d   =   Int32.Parse(ts.Days.ToString());
                                int   ts_m   =   Int32.Parse(ts.Minutes.ToString());
我发现一个问题

ts_d是以超过24小时算一天的,而我是要求就算只相差一分钟,超过午夜24点就算第二天

比如   07年1.12   23:59分   到   07年1.13   00:1分我是以一天算的
但int   ts_d   =   Int32.Parse(ts.Days.ToString());必须到07年1.13   23:59分   以上才算一天

怎么解决这个问题啊

------解决方案--------------------
//把时间部分清0
DateTime dt1 = DateTime.Parse(ThisTime)
dt1 = new DateTime(dt1.Year,dt1.Month,dt1.Day);
DateTime dt2 = DateTime.Parse( "2007-01-12 17:12:13.000 ")
dt2 = new DateTime(dt2.Year,dt2.Month,dt2.Day);
System.TimeSpan ts = dt2 - dt1;