whycrzg
2021-04-06 c773d0c150a4d90003bc7e3c776fe09e871cab30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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")));
 
    }
 
}