首先:加入依赖
<!-- 日期工具栏依赖 --> <dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> </dependency>
private String getDayOfWeek(DateTime dateTime) { String dayOfWeek = ""; switch (dateTime.getDayOfWeek()) { case DateTimeConstants.SUNDAY: dayOfWeek = "周日"; break; case DateTimeConstants.MONDAY: dayOfWeek = "周一"; break; case DateTimeConstants.TUESDAY: dayOfWeek = "周二"; break; case DateTimeConstants.WEDNESDAY: dayOfWeek = "周三"; break; case DateTimeConstants.THURSDAY: dayOfWeek = "周四"; break; case DateTimeConstants.FRIDAY: dayOfWeek = "周五"; break; case DateTimeConstants.SATURDAY: dayOfWeek = "周六"; default: break; } return dayOfWeek; }
得拿到数据,遍历时间
//把日期获取对应星期几 for (BookingScheduleRuleVo bookingScheduleRuleVo : ruleVos){ Date workDate = bookingScheduleRuleVo.getWorkDate(); String dayOfWeek = this.getDayOfWeek(new DateTime(workDate)); bookingScheduleRuleVo.setDayOfWeek(dayOfWeek); }