using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test
{
class Program
{
static void Main(string[] args)
{
DateTime dt = Convert.ToDateTime("2017-10-24 18:34:23");
string time = "2017-10-10 20:34:23"; //dt.Subtract(time) dt.Days=13
Console.WriteLine(dt.Subtract(Convert.ToDateTime(time)).Days);
DateTime Time = Convert.ToDateTime(time).Date;
TimeSpan ts = dt.Date.Subtract(Time); //dt.Subtract(time) dt.Days=14
int day = ts.Days;
//Console.WriteLine("{0},{1}", dt, time);
Console.WriteLine(day);
Console.Read();
}
}
}
两个时间相减
本文转载:CSDN博客