public class timerTest {
public static void main(String[] args) {
SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日: HH:mm:ss") ;
Date firstTime=null ;
try {
firstTime =sdf.parse("2022年09月10日: 20:10:30") ;
} catch (ParseException e) {
e.printStackTrace();
}
Timer timer=new Timer() ;
timer.schedule(new TimerTask() {
@Override
public void run() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日: HH:mm:ss");
String nowTime = sdf.format(new Date());
System.out.println(nowTime + "完成一次云备份");
}
}, firstTime, 1000 * 20);
}
}
/*
class logTimerTest extends TimerTask {
@Override
public void run() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日: HH:mm:ss");
String nowTime = sdf.format(new Date());
System.out.println(nowTime + "完成一次云备份");
}
}
*/