zoukankan      html  css  js  c++  java
  • asp.net显示评论的时候为几天前的格式

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

    效果如图:


    代码如下:

     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 "刚刚";
               }
           }
        }

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

  • 相关阅读:
    [SDOI2015]星际战争
    [SDOI2016]生成魔咒
    hdu3311
    [ZJOI2011]最小割
    P3331 [ZJOI2011]礼物(GIFT)
    [ZJOI2010]贪吃的老鼠
    状压dp-----三进制
    noip2016 天天爱跑步
    概率期望dp
    poj2186
  • 原文地址:https://www.cnblogs.com/jchubby/p/4429757.html
Copyright © 2011-2022 走看看