Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Timer;
import java.util.TimerTask;

public class Main {

    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 {
            Main thisObj = new Main();

            public void run() {
                String todaysdate = thisObj.CurrentDate();
                System.out.println(todaysdate);
            }
        }
        Timer timer = new Timer();
        timer.schedule(new SayHello(), 0, 5000);
    }

}