计算时间差

        /// <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;
        }

 

上一篇:nginx之location、inmp架构详解、BBS项目部署


下一篇:细说PHP第2版高洛峰