@ApiOperation("获取周时间的区间值")
private void getWeekTimeSection(int weekIndex)
{
//weekIndex为前几周的周数,如:获取当前时间前第二周的时间 weekIndex=2
//获取本周第一天
Calendar cal=Calendar.getInstance();
cal.add(Calendar.WEEK_OF_MONTH, 0);
cal.set(Calendar.DAY_OF_WEEK, 2);
Date first=cal.getTime();
Date last=cal.getTime();
String firstString= new SimpleDateFormat("yyyy-MM-dd").format(first)+" 00:00:00";
String lastString= new SimpleDateFormat("yyyy-MM-dd").format(last)+" 23:59:59";
LocalDateTime firstTime = LocalDateTime.parse(firstString, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
LocalDateTime lastTime = LocalDateTime.parse(lastString, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
firstTime=firstTime.plusDays(-(weekIndex* 7L)); //开始时间
lastTime=lastTime.plusDays(-(weekIndex*7L-6)); //结束时间
}
@ApiOperation("获取当前时间")
private String getDateByString() {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
return df.format(new Date());
}
|