123
This commit is contained in:
@@ -7,11 +7,22 @@ import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
|
||||
public class CaiDateUtil {
|
||||
|
||||
|
||||
/**
|
||||
* 计算时间相差秒数
|
||||
* 前者-后者 的差值
|
||||
*/
|
||||
public static long diff(LocalDateTime before, LocalDateTime after){
|
||||
return ChronoUnit.SECONDS.between(after, before);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static LocalDate getLastWeekOne(LocalDate date){
|
||||
return date.plusWeeks(-1)
|
||||
.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
||||
@@ -29,11 +40,6 @@ public class CaiDateUtil {
|
||||
}
|
||||
|
||||
|
||||
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());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user