Java8引入的LocalDateTime,LocalDate,LocalTime
public static void main(String[] args) {
Instant now = Instant.now();
LocalDateTime start = LocalDateTime.of(2018, 7, 24, 0, 0);
LocalDateTime end = LocalDateTime.of(2020, 7, 24, 23, 59);
final ZoneId myLocalZone = ZoneId.of("GMT+8");
if (now.isAfter(start.atZone(myLocalZone).toInstant())
&& now.isBefore(end.atZone(myLocalZone).toInstant())) {
System.out.println("hahah");
}
}
实体类中
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
知识拓展
Java8 Instant类
参考 https://blog.csdn.net/meteorsshower2013/article/details/8938261
JDK 1.8中Instant时间戳类,Duration类,Period类,等一些与事件相关的类和接口
参考 https://blog.csdn.net/yuyuyu1111112/article/details/79187541