asp.net显示评论的时候为几天前的格式

来源:互联网 发布:逆战跳高箱子宏数据 编辑:程序博客网 时间:2024/05/21 20:29

自己做的一个小项目实现的功能,做个记录先~

效果如图:


代码如下:

 public static  class TimerHelper    {       public static string GetTimeSpan(TimeSpan time)//TimeSpan为两个DateTime进行计算之后产生的类型,使用时传入当前时间-发表评论的时间即可       {           if (time.TotalDays >= 365)           {               return Math.Floor(time.TotalDays / 365) + "年前";           }           else if (time.TotalDays >= 30)           {               return Math.Floor(time.TotalDays / 30) + "月前";           }           else if (time.TotalDays >= 1)           {               return Math.Floor(time.TotalDays) + "天前";           }           else if (time.TotalHours >= 1)           {               return Math.Floor(time.TotalHours) + "小时前";           }           else if (time.TotalMinutes >= 1)           {               return Math.Floor(time.TotalMinutes) + "分钟前";           }           else           {               return "刚刚";           }       }    }

简单明了~还是要记一下吧= =省的忘记

0 0
原创粉丝点击