C# TimeSpan时间相减

来源:互联网 发布:数控车螺纹g76编程实例 编辑:程序博客网 时间:2024/06/11 05:48
                        <% BLLLucky bllLucky1 = new BLLLucky();                           List<EntityLuckyRunTime> luckyList = bllLucky1.GetLuckyRunTimeByType(6, 10);                           foreach (EntityLuckyRunTime item in luckyList)                           {                               DateTime time = item.CreateDate;                               string strMobile = bllLucky1.getMobile(item.Mobile);                               TimeSpan ts = DateTime.Now - time;                               //string strTime = Math.Round(ts.TotalHours, 0).ToString();                               string strTime = "";                               double seconds = Math.Round(ts.TotalSeconds,0);//秒                               if (seconds < 60)                                   strTime = "刚刚";                               if (seconds >= 60 && seconds < 3600)                                   strTime =  Math.Round(seconds/60,0) + "分钟前";                               if (seconds >= 3600)                                   strTime = Math.Round(seconds / 3600, 0) + "小时前"; ;                                                 <%} %>