1.TimerTask(延迟操作)
貌似只有在controller层才有效果具体什么原因不清楚
Timer timer=new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
//定时过后需要操作的代码块
System.out.println("时间到");
this.cancel();
}
}, 5000);//毫秒
System.out.println("请等待5s");
执行顺序如下:
2.DateTimeFormatter(LocalDateTime )与SimpleDateFormat
之前一直用 SimpleDateFormat 最近公司才通知我 改成DateTimeFormatter
然后查了一下 和 SimpleDateFormat 相比,DateTimeFormatter(1.8新特性) 是线程安全的。
LocalDateTime 能够快速地获取年、月、日、下一月等。(查看api)
首先用LocalDateTime获取当前时间可以 精确到毫秒 比new Date()好用
LocalDateTime time=LocalDateTime.now();
结果如下(不满意格式):
在自定义格式DateTimeFormatter
DateTimeFormatter fmt=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String ti=fmt.format(time);
System.out.println(ti);
结果如下:
3.LocalDate与LocalTime
总结出LocalDate+LocalTime=LocalDateTime
LocalDate d=LocalDate.now();//2019-09-25
LocalTime t=LocalTime.now();//10:28:57.713
System.out.println(d+" "+t);
结果如下: