| | |
| | |
|
| | | 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);
|
| | | }
|
| | |
|