public static Map<String, String> getSpecialDate(String type) {
Calendar calendar = Calendar.getInstance();
Map<String, String> resultMap = new HashMap<>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
if ("12".equals(type)) {
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
calendar.add(Calendar.DATE, 7);
String monday = dateFormat.format(calendar.getTime());
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
String sunday = dateFormat.format(calendar.getTime());
resultMap.put("date1", monday);
resultMap.put("date2", sunday);
return resultMap;
}
if ("11".equals(type)) {
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
calendar.add(Calendar.DATE, -7);
String monday = dateFormat.format(calendar.getTime());
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
String sunday = dateFormat.format(calendar.getTime());
resultMap.put("date1", monday);
resultMap.put("date2", sunday);
return resultMap;
}
if ("10".equals(type)) {
calendar.add(Calendar.DATE, 1);
String begin = dateFormat.format(calendar.getTime());
resultMap.put("date1", begin);
return resultMap;
}
if ("9".equals(type)) {
calendar.add(Calendar.DATE, -1);
String begin = dateFormat.format(calendar.getTime());
resultMap.put("date1", begin);
return resultMap;
}
if ("8".equals(type)) {
calendar.add(Calendar.YEAR, -1);
calendar.set(Calendar.MONTH, 0);
calendar.set(Calendar.DATE, 1);
String begin = dateFormat.format(calendar.getTime());
calendar.set(Calendar.MONTH, 11);
calendar.set(Calendar.DATE, 31);
String end = dateFormat.format(calendar.getTime());
resultMap.put("date1", begin);
resultMap.put("date2", end);
return resultMap;
}
if ("7".equals(type)) {
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.MONTH, -1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
String firstDayOfMonth = dateFormat.format(calendar.getTime());
calendar.add(Calendar.MONTH, 1);
calendar.set(Calendar.DAY_OF_MONTH, 0);
String lastDayOfMonth = dateFormat.format(calendar.getTime());
resultMap.put("date1", firstDayOfMonth);
resultMap.put("date2", lastDayOfMonth);
return resultMap;
}
if ("5".equals(type)) {
calendar.set(Calendar.MONTH, 0);
calendar.set(Calendar.DATE, 1);
String begin = dateFormat.format(calendar.getTime());
calendar.set(Calendar.MONTH, 11);
calendar.set(Calendar.DATE, 31);
String end = dateFormat.format(calendar.getTime());
resultMap.put("date1", begin);
resultMap.put("date2", end);
return resultMap;
}
if ("4".equals(type)) {
int currentMonth = calendar.get(Calendar.MONTH) + 1;
if (currentMonth >= 1 && currentMonth <= 3)
calendar.set(Calendar.MONTH, 0);
else if (currentMonth >= 4 && currentMonth <= 6)
calendar.set(Calendar.MONTH, 3);
else if (currentMonth >= 7 && currentMonth <= 9)
calendar.set(Calendar.MONTH, 4);
else if (currentMonth >= 10 && currentMonth <= 12)
calendar.set(Calendar.MONTH, 9);
calendar.set(Calendar.DATE, 1);
String begin = dateFormat.format(calendar.getTime());
calendar.add(Calendar.MONTH, 3);
calendar.add(Calendar.DATE, -1);
String end = dateFormat.format(calendar.getTime());
resultMap.put("date1", begin);
resultMap.put("date2", end);
return resultMap;
}
if ("3".equals(type)) {
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.MONTH, 0);
calendar.set(Calendar.DAY_OF_MONTH, 1);
String firstDayOfMonth = dateFormat.format(calendar.getTime());
calendar.add(Calendar.MONTH, 1);
calendar.set(Calendar.DAY_OF_MONTH, 0);
String lastDayOfMonth = dateFormat.format(calendar.getTime());
resultMap.put("date1", firstDayOfMonth);
resultMap.put("date2", lastDayOfMonth);
return resultMap;
}
if ("2".equals(type)) {
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
String monday = dateFormat.format(calendar.getTime());
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
String sunday = dateFormat.format(calendar.getTime());
resultMap.put("date1", monday);
resultMap.put("date2", sunday);
return resultMap;
}
if ("1".equals(type)) {
calendar.setTimeInMillis(System.currentTimeMillis());
resultMap.put("date1", dateFormat.format(calendar.getTime()));
return resultMap;
}
return null;
}
|