SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHH");
Date parse = sdf.parse(String.valueOf(temp));
LocalDate taskLocalDate=parse.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
//相差天数
long dayLength = startDay.until(nowDate, ChronoUnit.DAYS);
----------------------------------------------------------Date转字符串封装方法
private String date2Str(Date date){
LocalDateTime localDateTime = date.toInstant().atOffset(ZoneOffset.of("+8")).toLocalDateTime();
return localDateTime.format((DateTimeFormatter.ofPattern("yyyy-MM-dd")));
}
---------------------------特定天数相差及求出中间每一天带顺序
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
Date parse= null;
try {
parse = sdf.parse("20201024");
LocalDate localDate=parse.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
Date parse2=sdf.parse("20201026");
LocalDate localDate2=parse2.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
//相差天数
long DateLength=localDate.until(localDate2, ChronoUnit.DAYS);
DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd");
System.out.println(DateLength);
for (int k = 0; k <=DateLength ; k++) {
LocalDate tempDate = localDate2.minusDays(k);
String dateStr = df.format(tempDate);
System.out.println(dateStr);
}
} catch (ParseException e) {
e.printStackTrace();
}
java 时间日期 字符串转Date转LocalDate 后 计算相差天数
最新推荐文章于 2024-08-22 14:59:42 发布