其他分享
首页 > 其他分享> > 计算时间差

计算时间差

作者:互联网

        /// <summary>
        /// 时间差
        /// </summary>
        /// <param name="dateBegin">开始时间</param>
        /// <param name="dateEnd">结束时间</param>
        /// <returns>返回单位秒</returns>
        public static int ExecDateDiff(DateTime dateBegin, DateTime dateEnd)
        {
            TimeSpan ts1 = new TimeSpan(dateBegin.Ticks);
            TimeSpan ts2 = new TimeSpan(dateEnd.Ticks);
            TimeSpan ts3 = ts1.Subtract(ts2).Duration();
            int Seconds = ts3.Seconds;
            if (ts3.Minutes>0)
            {
                Seconds += ts3.Minutes * 60;
            }
            if (ts3.Hours>0)
            {
                Seconds += ts3.Hours * 60 * 60;
            }
            if (ts3.Days>0)
            {
                Seconds += ts3.Days * 60 * 60 * 24;
            }
            return Seconds;
        }

 

标签:TimeSpan,Seconds,Ticks,时间差,60,int,计算,ts3
来源: https://www.cnblogs.com/s666/p/14990396.html