C# 计算两个时间点相差的 时、分、秒

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/BaiYangShouTong/article/details/54573431
      //计算两个时间点相差的 时、分、秒
        public void TimeSpan()
        {
            //c#对时间差,有一个专门的类进行封装,TimeSpan.cs;


            System.DateTime pauseT = System.Convert.ToDateTime("2017-1-15 13:30:34");


            System.DateTime resumeT = System.DateTime.Now;


            //Debug.Log(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));


            System.TimeSpan ts1 = new System.TimeSpan(pauseT.Ticks);


            System.TimeSpan ts2 = new System.TimeSpan(resumeT.Ticks);


            System.TimeSpan tsSub = ts1.Subtract(ts2).Duration();


            //Debug.Log("Time  Span" + tsSub.Days + "   " + tsSub.Hours + "  " + tsSub.Minutes);


            //tsSub.Days:相差天数;
            //tsSub.Hours:相差小时;
            //tsSub.Minutes:相差分钟;
        }

猜你喜欢

转载自blog.csdn.net/BaiYangShouTong/article/details/54573431