package com.whyc.timer;
|
|
import org.springframework.context.annotation.Configuration;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import java.time.LocalDateTime;
|
import java.time.format.DateTimeFormatter;
|
|
/**
|
* 定时器任务,可以定期执行某项任务
|
*/
|
|
@Configuration
|
@EnableScheduling
|
public class Timer {
|
|
//@Scheduled(cron = "0/60 * * * * *")
|
public void timer1() {
|
//获取当前时间
|
LocalDateTime localDateTime = LocalDateTime.now();
|
System.out.println("当前时间为:" + localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
}
|
|
}
|