标签:turn asp.net form str int lda mat floor time
public static string DateFormatToString(DateTime dt)
{
TimeSpan span = (DateTime.Now - dt).Duration();
if (span.TotalDays > 60)
{
return dt.ToString("yyyy-MM-dd");
}
else if (span.TotalDays > 30)
{
return "1个月前";
}
else if (span.TotalDays > 14)
{
return "2周前";
}
else if (span.TotalDays > 7)
{
return "1周前";
}
else if (span.TotalDays > 1)
{
return string.Format("{0}天前", (int)Math.Floor(span.TotalDays));
}
else if (span.TotalHours > 1)
{
return string.Format("{0}小时前", (int)Math.Floor(span.TotalHours));
}
else if (span.TotalMinutes > 1)
{
return string.Format("{0}分钟前", (int)Math.Floor(span.TotalMinutes));
}
else if (span.TotalSeconds >= 1)
{
return string.Format("{0}秒前", (int)Math.Floor(span.TotalSeconds));
}
else
{
return "1秒前";
}
}
asp.net 格式化显示时间为几个月,几天前,几小时前,几分钟前,或几秒前
标签:turn asp.net form str int lda mat floor time
原文地址:http://www.cnblogs.com/zhanbicheng/p/6757503.html