//获取星期几
Calendar calendar = Calendar.getInstance();
calendar.setTime(oaHumanClockCountVo.getCreateTime());
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK)-1;
//比较两个时间之间相差多少分钟
Integer def = Math.toIntExact((clockDate.getTime() - startTime.getTime()) / (60 * 1000));
//获取指定日期昨天的日期
Date date=new Date();
Calendar calendar1 = Calendar.getInstance();
calendar1.setTime(date);
calendar1.add(Calendar.DAY_OF_MONTH, -1);
Date previousDate = calendar1.getTime();
//把Date转换为yyyy-MM-dd HH:mm:ss
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateInfo=formatter.format(bo.getEndDate());
//获取String格式:yyy/MM/dd 星期几
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd EEEE");
// 获取当前时间
Date currentDate = new Date();
// 格式化日期并输出
String formattedDate = sdf.format(currentDate);
//获取两个日期之间所有日期的列表(如果想格式化,参考上面的代码)
LocalDate localDate1 = vo.getStartDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate localDate2 = vo.getEndDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
List<Date> dateList = Stream.iterate(localDate1, date -> date.plusDays(1))
.limit(localDate1.until(localDate2).getDays() + 1)
.map(date -> Date.from(date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()))
.collect(Collectors.toList());
近来为了实现考勤,难免和时间打交道多一点,相关的操作就老是卡壳,特意写一篇文章来纪念一下我掉的头发。