import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
public class DateUtils{
/**
* LocalDate转Date
* @param localDate
* @return
*/
public static Date localDate2Date(LocalDate localDate) {
ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
return Date.from(zonedDateTime.toInstant());
}
/**
* Date转LocalDate
* @param date
*/
public static LocalDate date2LocalDate(Date date) {
return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
}
/**
* 时间差
*/
public static Long subtraction (Date startDate, Date endDate ) {
ocalDateTime endDateLocal = endDate .toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
LocalDateTime startDateLocal = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
long daysDiff = ChronoUnit.MINUTES.between(startDateLocal ,endDateLocal );
return daysDiff;
}
}
Date转LocalDate
最新推荐文章于 2024-07-14 16:04:57 发布