C# asp.net 比较两个时间的差求天数

  string str1 = "2017-2-13 23:59:59";
            string str2 = "2017-2-14 0:00:01";
            DateTime d1 = Convert.ToDateTime(str1);
            DateTime d2 = Convert.ToDateTime(str2);
            DateTime d3 = Convert.ToDateTime(string.Format("{0}-{1}-{2}", d1.Year, d1.Month, d1.Day));
            DateTime d4 = Convert.ToDateTime(string.Format("{0}-{1}-{2}", d2.Year, d2.Month, d2.Day));
            int days = (d4 - d3).Days;

 

posted @ 2017-04-28 14:05  幽冥狂_七  阅读(1053)  评论(0编辑  收藏  举报