C# DateTime类型的日期时间变量做差之后是存在正负的

代码:

        static void Main(string[] args)
        {
            DateTime datebefore = DateTime.Now.AddHours(100D);
            DateTime dateafter = DateTime.Now.AddHours(-100D);
            Console.WriteLine((datebefore-DateTime.Now));
            Console.WriteLine((dateafter-DateTime.Now));
            Console.ReadLine();
        }

 计算结果:

总结:

两个日期时间做查,之前的时间减去之后的时间得出的时间为负。之后的时间减去之前的时间为正。得出的时间并不是绝对值的时间段。 

猜你喜欢

转载自blog.csdn.net/wudong121/article/details/81240469