import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class TimerTest {
public static void main(String[] args) {
Timer timer=new Timer();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date=null;
try {
date=sdf.parse("2021-4-18 15:19:00");
} catch (ParseException e) {
e.printStackTrace();
}
timer.schedule(new logTimerTest(),date,1000*5);
}
}
class logTimerTest extends TimerTask{
@Override
public void run() {
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String strTime=sdf.format(new Date());
System.out.println(strTime+": 完成一次备份");
}
}