Commit fc38528c authored by lisong's avatar lisong

更新

parent 23c88d80
......@@ -836,6 +836,69 @@ public class DateUtils {
return dates;
}
public static List<Map<String, String>> getWeeksMapInterval(String date){
List<Map<String, String>> dates = new ArrayList<>();
String year = date.substring(0,4);
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
Date date1 = null;
try {
date1 = dateFormat.parse(date);
} catch (ParseException e) {
System.out.println("获取当前月自然周,日期格式转换错误!11");
e.printStackTrace();
}
Calendar calendar = new GregorianCalendar();
calendar.setTime(date1);
int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
int count = 0;
for (int i = 1; i <= days; i++) {
DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
Date date2 = null;
try {
date2 = dateFormat1.parse(date + "-" + i);
} catch (ParseException e) {
System.out.println("获取当前月自然周,日期格式转换错误!22");
e.printStackTrace();
}
calendar.clear();
calendar.setTime(date2);
int k = new Integer(calendar.get(Calendar.DAY_OF_WEEK));
int startDay = 0;
int endDay = 0;
// 若当天是周日
if (k == 1) {
count++;
if (i - 6 <= 1) {
startDay = 1;
} else {
startDay = i - 6;
}
endDay = i;
}
// 若是本月最好一天,且不是周日
if (k != 1 && i == days) {
count++;
startDay = i - k + 2;
endDay = i;
}
if(startDay != 0 && endDay != 0){
String s = year + "第" + getWeekOfYear(date2) + "周" + "(" + date.substring(5) + "月" + startDay +
"日至" + date.substring(5) + "月" + endDay + "日" +")";
String weekStart = year + "-"+ date.substring(5) +"-" +startDay +" 00:00:00";
String weekEnd = year + "-"+ date.substring(5) +"-" +endDay +" 23:59:59";
HashMap<String, String> map = new HashMap<>();
map.put("name",s);
map.put("weekStart",weekStart);
map.put("weekEnd",weekEnd);
dates.add(map);
}
}
return dates;
}
/**
* 获取一年的第几周
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment