C# 获取时间差(几天前,几小时前,几分钟前,几秒前)

 /// <summary>
 3         /// 获取时间差
 4         /// </summary>
 5         /// <param name="getTime">数据库时间</param>
 6         /// <returns>时间差</returns>
 7         private string GetTime(BsonString getTime)
 8         {
 9             var time1 = DateTime.ParseExact(Convert.ToString(getTime), "yyyy-MM-dd HH:mm:ss", null);
10             var time = DateTime.Now - time1;
11 
12             if (time.TotalHours > 24)
13             {
14                 return Math.Floor(time.TotalDays) + "天前";
15             }
16             if (time.TotalHours > 1)
17             {
18                 return Math.Floor(time.TotalHours) + "小时前";
19             }
20             if (time.TotalMinutes > 1)
21             {
22                 return Math.Floor(time.TotalMinutes) + "分钟前";
23             }
24             return Math.Floor(time.TotalSeconds) + "秒前";
25         }

 

C# 获取时间差(几天前,几小时前,几分钟前,几秒前)

上一篇:AcWing287 积蓄程度(换根dp)


下一篇:linux 卸载软件不卸载依赖