42 lines
1.1 KiB
Java
42 lines
1.1 KiB
Java
package com.ruoyi.cai.util;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
import java.time.DayOfWeek;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.temporal.TemporalAdjusters;
|
|
|
|
public class CaiDateUtil {
|
|
|
|
|
|
public static LocalDate getLastWeekOne(LocalDate date){
|
|
return date.plusWeeks(-1)
|
|
.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
|
}
|
|
|
|
public static String localDateTimeToString(LocalDateTime localDateTime){
|
|
return localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
}
|
|
|
|
public static LocalDateTime toDataSecond(Long date){
|
|
if(date == null){
|
|
return null;
|
|
}
|
|
return DateUtil.date(date*1000).toLocalDateTime();
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
LocalDate one = getLastWeekOne(LocalDate.now());
|
|
System.out.println(one.format(DateTimeFormatter.ofPattern("yyyyMMdd")));
|
|
}
|
|
|
|
public static String getCurrentTimeStr() {
|
|
return localDateTimeToString(LocalDateTime.now());
|
|
|
|
}
|
|
}
|