Calling a function every 10 minutes

前端 未结 5 2175
有刺的猬
有刺的猬 2020-12-05 14:05

I\'m not an expert, just a beginner. So I kindly ask that you write some code for me.

If I have two classes, CLASS A and CLASS B, and insid

5条回答
  •  情歌与酒
    2020-12-05 14:15

    public class datetime {
    
        public String CurrentDate() {
    
            java.util.Date dt = new java.util.Date();
            java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
            String currentTime = sdf.format(dt);
            return currentTime;
    
        }
    
        public static void main(String[] args) {
            class SayHello extends TimerTask {
    
                datetime thisObj = new datetime();
    
                public void run() {
                    String todaysdate = thisObj.CurrentDate();
                    System.out.println(todaysdate);
                }
            }
            Timer timer = new Timer();
            timer.schedule(new SayHello(), 0, 5000); 
        }
    }
    

提交回复
热议问题