|
|
@@ -8,13 +8,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
import java.time.DayOfWeek;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.TemporalAdjusters;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Calendar;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -176,75 +174,50 @@ public class ScreenUtil {
|
|
|
*/
|
|
|
private String TimeFormat(String value){
|
|
|
String formatValue = "";
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ LocalDate localDate = LocalDate.now();
|
|
|
switch (value) {
|
|
|
case "today" :
|
|
|
- formatValue = simpleDateFormat.format(calendar.getTime());
|
|
|
+ formatValue = localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
break;
|
|
|
case "yesterday" :
|
|
|
- calendar.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
- formatValue = simpleDateFormat.format(calendar.getTime());
|
|
|
+ formatValue = localDate.plusDays(-1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
break;
|
|
|
case "week" :
|
|
|
- calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
|
|
|
- formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
|
|
|
- calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
|
|
|
- formatValue += simpleDateFormat.format(calendar.getTime());
|
|
|
+ formatValue = localDate.plusWeeks(0).with(DayOfWeek.MONDAY).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
|
|
|
+ + localDate.plusWeeks(0).with(DayOfWeek.SUNDAY).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
break;
|
|
|
case "lastweek" :
|
|
|
- calendar.add(Calendar.WEEK_OF_YEAR, -1);
|
|
|
- calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
|
|
|
- formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
|
|
|
- calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
|
|
|
- formatValue += simpleDateFormat.format(calendar.getTime());
|
|
|
+ formatValue = localDate.plusWeeks(-1).with(DayOfWeek.MONDAY).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
|
|
|
+ + localDate.plusWeeks(-1).with(DayOfWeek.SUNDAY).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
break;
|
|
|
case "month" :
|
|
|
- calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
- formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
|
|
|
- calendar.add(Calendar.MONTH, 1);
|
|
|
- calendar.set(Calendar.DAY_OF_MONTH, 0);
|
|
|
- formatValue += simpleDateFormat.format(calendar.getTime());
|
|
|
+ formatValue = localDate.plusMonths(0).with(TemporalAdjusters.firstDayOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
|
|
|
+ + localDate.plusWeeks(0).with(TemporalAdjusters.lastDayOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
break;
|
|
|
case "lastmonth" :
|
|
|
- calendar.add(Calendar.MONTH, -1);
|
|
|
- calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
- formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
|
|
|
- calendar.add(Calendar.MONTH, 1);
|
|
|
- calendar.set(Calendar.DAY_OF_MONTH, 0);
|
|
|
- formatValue += simpleDateFormat.format(calendar.getTime());
|
|
|
+ formatValue = localDate.plusMonths(-1).with(TemporalAdjusters.firstDayOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
|
|
|
+ + localDate.plusMonths(-1).with(TemporalAdjusters.lastDayOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
break;
|
|
|
case "quarter" :
|
|
|
- formatValue = simpleDateFormat.format(quarterStart(0).getTime()) + ",";
|
|
|
- Calendar c1 = quarterStart(0);
|
|
|
- c1.add(Calendar.MONTH, 2);
|
|
|
- formatValue += simpleDateFormat.format(c1.getTime());
|
|
|
+ formatValue = quarterStart(0).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
|
|
|
+ + quarterStart(0).plusMonths(2).with(TemporalAdjusters.lastDayOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
break;
|
|
|
case "lastquarter" :
|
|
|
- formatValue = simpleDateFormat.format(quarterStart(-2).getTime()) + ",";
|
|
|
- Calendar c2 = quarterStart(0);
|
|
|
- c2.add(Calendar.MONTH, 2);
|
|
|
- formatValue += simpleDateFormat.format(c2.getTime());
|
|
|
+ formatValue = quarterStart(-1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
|
|
|
+ + quarterStart(-1).plusMonths(2).with(TemporalAdjusters.lastDayOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ formatValue = "";
|
|
|
break;
|
|
|
case "halfyear" :
|
|
|
- calendar.add(Calendar.MONTH, -6);
|
|
|
- calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
- formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
|
|
|
- calendar = Calendar.getInstance();
|
|
|
- formatValue += simpleDateFormat.format(calendar.getTime());
|
|
|
+ formatValue = localDate.plusMonths(-6).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
|
|
|
+ + localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
break;
|
|
|
case "year" :
|
|
|
- calendar.set(Calendar.DAY_OF_YEAR, 1);
|
|
|
- formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
|
|
|
- calendar.roll(Calendar.DAY_OF_YEAR, -1);
|
|
|
- formatValue += calendar.getTime();
|
|
|
+ formatValue = localDate.plusYears(0).with(TemporalAdjusters.firstDayOfYear()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
|
|
|
+ + localDate.plusWeeks(0).with(TemporalAdjusters.firstDayOfYear()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
break;
|
|
|
case "lastyear" :
|
|
|
- calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 1);
|
|
|
- calendar.set(Calendar.DAY_OF_YEAR, 1);
|
|
|
- formatValue = simpleDateFormat.format(calendar.getTime()) + ",";
|
|
|
- calendar.roll(Calendar.DAY_OF_YEAR, -1);
|
|
|
- formatValue += calendar.getTime();
|
|
|
+ formatValue = localDate.plusYears(-1).with(TemporalAdjusters.firstDayOfYear()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + ","
|
|
|
+ + localDate.plusWeeks(-1).with(TemporalAdjusters.firstDayOfYear()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
break;
|
|
|
default:
|
|
|
formatValue = value;
|
|
|
@@ -253,9 +226,9 @@ public class ScreenUtil {
|
|
|
return formatValue;
|
|
|
}
|
|
|
|
|
|
- private static Calendar quarterStart(int offset) {
|
|
|
- final Calendar calendar = Calendar.getInstance();
|
|
|
- int month = calendar.get(Calendar.MONTH);//当月
|
|
|
+ private static LocalDate quarterStart(int offset) {
|
|
|
+ final LocalDate date = LocalDate.now().plusMonths(offset * 3);
|
|
|
+ int month = date.getMonth().getValue();//当月
|
|
|
int start = 0;
|
|
|
if (month >= 1 && month <= 3) {//第一季度
|
|
|
start = 1;
|
|
|
@@ -269,8 +242,6 @@ public class ScreenUtil {
|
|
|
start = 12;
|
|
|
month = 14;
|
|
|
}
|
|
|
- calendar.add(Calendar.MONTH,start - month);
|
|
|
- calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
- return calendar;
|
|
|
+ return date.plusMonths(start - month).with(TemporalAdjusters.firstDayOfMonth());
|
|
|
}
|
|
|
}
|