C# 计算两个时间差返回年月日时分秒

	/// 
    /// 日期帮助类
    /// 
    public class DateTimeHelper
    {
        /// 
        /// 计算两个时间差(年月日时分秒)
        /// 
        /// 
        /// 
        /// 
        public static string DateFormat(DateTime begin, DateTime end)
        {
            //ts.Days  //这是相差的天数
            //ts.Hours     //这是相差的小时数,
            //ts.Minutes    //这是相差的分数
            TimeSpan ts = end - begin;
            string msg = $"{ts.Hours}小时{ts.Minutes}分钟{ts.Seconds}秒";
            return msg;
        }
    }

你可能感兴趣的:(C#通用方法,c#)