private static final String week = "一二三四五六日";
List<Integer> dayOfWeekLikst = Arrays.asList("2,3,5,6,7".split(",")).stream().map(Integer::valueOf).collect(toList());
int startIndex = 0;
StringBuilder sb = new StringBuilder();
String startTime = "";
String endTime = "";
for (int i = 0; i < dayOfWeekLikst.size(); i++) {
String substring = week.substring(startIndex, dayOfWeekLikst.get(i) - 1);
if (StringUtils.isNotBlank(substring)) {
char[] chars = substring.toCharArray();
if (chars.length >= 2) {
sb.append(String.format("周%s至周%s、", chars[0], chars[chars.length - 1]));
} else if (chars.length == 1) {
sb.append(String.format("周%s、", chars[0]));
}
}
if (i == dayOfWeekLikst.size() - 1) {
String substring2 = week.substring(dayOfWeekLikst.get(i));
if (StringUtils.isNotBlank(substring2)) {
char[] chars = substring2.toCharArray();
if (chars.length >= 2) {
sb.append(String.format("周%s至周%s", chars[0], chars[chars.length - 1]));
} else if (chars.length == 1) {
sb.append(String.format("周%s", chars[0]));
}
} else {
//截去最后一个符号
sb.replace(sb.length() - 1, sb.length(), "");
}
}
startIndex = dayOfWeekLikst.get(i);
}
计算不可用周数
最新推荐文章于 2024-08-23 15:54:50 发布