Java:LocalDateTime获取今天的开始时间和结束时间

代码示例

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

猜你喜欢

转载自blog.csdn.net/mouday/article/details/130286686
今日推荐