前台代码如下:
<%# FormatSeeTime(Eval("seetime"))%>
后台代码如下:
protected string FormatSeeTime(object caption)//格式化历史记录的显示时间。
{
DateTime d1 = DateTime.Parse(string.Format("{0:yyyy}-{0:MM}-{0:dd} {0:HH}:{0:mm}", caption));
DateTime d2 = DateTime.Parse(string.Format("{0:yyyy}-{0:MM}-{0:dd} {0:HH}:{0:mm}", DateTime.Now));
System.TimeSpan ND = d2 - d1;
int n = ND.Days; //天数差
int hn = ND.Hours; //小时差
if (n.ToString() == "0")
{ return "当天" + hn.ToString() + "时前"; }
else
{ return n.ToString() + "天" + hn.ToString() + "时前"; }
}
发表于 @ 2008年09月12日 15:00:00|评论(loading...)|编辑|收藏