admin
2020-05-20 98b1a0affd69bbe63223c21fdd2c404e8bedfccb
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/DynamicController.java
@@ -3,6 +3,7 @@
import java.io.PrintWriter;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@@ -25,7 +26,7 @@
import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
import com.yeshi.fanli.service.inter.dynamic.DynamicInfoService;
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.taobao.DaTaoKeUtil;
@@ -184,23 +185,47 @@
            String desc = "";
            if (value != null) {
               // 判断是否是同一天
               Calendar calendar = Calendar.getInstance();
               calendar.setTime(value);
               int y1 = calendar.get(Calendar.YEAR);//获取年份
               int d1 = calendar.get(Calendar.DAY_OF_YEAR);//获取年中第几天
               Date nowDate = new Date();
               Calendar calendar2 = Calendar.getInstance();
               calendar2.setTime(nowDate);
               int y2 = calendar2.get(Calendar.YEAR);//获取年份
               int d2 = calendar2.get(Calendar.DAY_OF_YEAR);//获取年中第几天
               long old = value.getTime();
               long now = System.currentTimeMillis();
               long oldDay = old / (1000 * 60 * 60 * 24L);
               long nowDay = now / (1000 * 60 * 60 * 24L);
               if (oldDay == nowDay) {// 同一天
                  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 = "昨天";
               long now = nowDate.getTime();
               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);
            }