代码示例

LocalDateTime now = LocalDateTime.now();

int year = now.getYear();
int month = now.getMonthValue();
int day = now.getDayOfMonth();
System.out.println(String.format("%d-%d-%d", year, month, day));
// 2023-4-21

LocalDateTime startTime = LocalDateTime.of(year, month, day, 0, 0, 0);
LocalDateTime endTime = LocalDateTime.of(year, month, day, 23, 59, 59);

System.out.println(startTime);
// 2023-04-21T00:00
System.out.println(endTime);
// 2023-04-21T23:59:59