本文共 681 字,大约阅读时间需要 2 分钟。
转自:http://www.cnblogs.com/zengxiangzhan/archive/2009/10/30/1592926.html
<% # GetOutTime(Eval( " 发布时间 " )) %> /// <summary> /// 离最近发表时间代码 /// </summary> /// <param name="dtime"> 发布时间 </param> /// <returns></returns> public static string GetOutTime(DateTime dtime) { DateTime dt = DateTime.Now; TimeSpan ts = ((TimeSpan)(dt - dtime)); int days = ts.Days; int hours = ts.Hours; int minutes = ts.Minutes; int milliseconds = ts.Milliseconds; if (days > 0 ) return string .Format( " 发布于{0}天前 " , days); if (hours > 0 ) return string .Format( " 发布于{0}小时前 " , hours); if (minutes > 0 ) return string .Format( " 发布于{0}分钟前 " , minutes); return string .Format( " 发布于{0}秒前 " , milliseconds); }