public static string CalculationTime(DateTime Starttime)
{
string timeString = "";
DateTime EndTime = DateTime.Now;
if (EndTime < Starttime)
return "开始时间不能大于当前时间";
TimeSpan span = EndTime - Starttime;
if (span.Days > 365)
timeString = (span.Days / 365).ToString() + "年前";
else if (span.Days > 30)
timeString = (span.Days / 30).ToString() + "个月前";
else if (span.Days > 0)
timeString = span.Days.ToString() + "天前";
else if (span.Hours > 0)
timeString = span.Hours.ToString() + "小时前";
else if (span.Minutes > 0)
timeString = span.Minutes.ToString() + "分钟前";
else if (span.Seconds > 0)
timeString = span.Seconds.ToString() + "秒前";
else
timeString = "刚刚";
return timeString;
}
计算时间差
最新推荐文章于 2022-02-15 14:19:29 发布