admin
2019-09-08 2db0485ab8aa814499adf49112c5aa9e4c9e78b2
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/DynamicController.java
@@ -199,21 +199,33 @@
               
               long old = value.getTime();
               long now = nowDate.getTime();
               long oldDay = old/ (1000 * 60 * 60 * 24L);
               long nowDay = now / (1000 * 60 * 60 * 24L);
               if (y1 == y2 && d1 == d2) {//判断是不是同一年的同一天
                  long cha = now - old;
                  if (cha < 1000 * 60 * 2L)
                     desc = "刚刚";
                  else if (cha < 1000 * 60 * 60L)
                     desc = (cha / (1000 * 60)) + "分钟前";
                  else
                     desc = (cha / (1000 * 60 * 60)) + "小时前";
               } else if (nowDay - oldDay == 1) {
                  desc = "昨天";
               if (y1 == y2) {
                  if (d1 == d2) {
                     long cha = now - old;
                     if (cha < 1000 * 60 * 2L) {
                        desc = "刚刚";
                     }else if (cha < 1000 * 60 * 60L) {
                        desc = (cha / (1000 * 60)) + "分钟前";
                     }else {
                        desc = (cha / (1000 * 60 * 60)) + "小时前";
                     }
                  } else if (d2 - d1 == 1) {
                     desc = "昨天";
                  } else {
                     desc = (d2 - d1) + "天前";
                  }
               } else {
                  desc = (nowDay - oldDay) + "天前";
                  int timeDistance = 0;
                  for (int i = y1; i < y2; i++) {
                     if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {
                        timeDistance += 366; // 闰年
                     } else {
                        timeDistance += 365; // 不是闰年
                     }
                  }
                  desc = timeDistance + (d2 - d1) + "天前";
               }
               return new JsonPrimitive(desc);
            }