/// <summary> /// 获取当前时间差 /// </summary> /// <param name="strTime"></param> /// <returns></returns> public static string GetTimeDiff(object strTime) { TimeSpan nowTime = new TimeSpan(DateTime.Now.Ticks); TimeSpan passTime = new TimeSpan(Convert.ToDateTime(strTime).Ticks); TimeSpan ts = nowTime.Subtract(passTime); if (ts.TotalDays >= 1) { return ((int)ts.TotalDays) + "天前"; } if (ts.TotalHours >= 1 && ts.TotalHours < 24) { return ((int)ts.TotalHours) + "小时前"; } if (ts.TotalMinutes >= 1 && ts.TotalMinutes < 60) { return ((int)ts.TotalMinutes) + "分钟前"; } if (ts.TotalSeconds >= 1 && ts.TotalSeconds < 60) { return ((int)ts.TotalSeconds) + "秒前"; } return "未知"; }