-
获取一天开始的时间点(0点0时0分0秒)
//获取字符串
String indicatorTradeDt = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd 00:00:00"));
//获取LocalDateTime对象
LocalDateTime todayStart = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
- 比较时间的大小(在一天的指定时间内做指定的事情)
在每天的9点到下午3点做指定的事情
LocalDateTime now = LocalDateTime.now();
LocalDateTime startTime = now.withHour(9).withMinute(0).withSecond(0);
LocalDateTime endTime = now.withHour(15).withMinute(0).withSecond(0);
if (now.isAfter(startTime)&&now.isBefore(endTime)){
//do something
}