JAVA日期当天0点0分0秒

LocalDateTime

LocalDateTime ldt = LocalDateTime.now();
LocalDateTime todayZero = LocalDateTime.of(ldt.getYear(), ldt.getMonthValue(), ldt.getDayOfMonth(), 0, 0, 0);
或
LocalDateTime.now().toLocalDate().atStartOfDay();

DateTimeFormatter

DateTimeFormatter DATE_ZERO_FORMAT = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDateTime ldt = LocalDateTime.now();
String todayZeroStr = ldt.format(DelegateActiveComp.DATE_ZERO_FORMAT);

SimpleDateFormat

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date activationTime = dateFormat.parse(dateFormat.format(new Date()));
posted @ 2023-12-12 11:03  原子切割员  阅读(459)  评论(0编辑  收藏  举报