Java tutorial
import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Timer; import java.util.TimerTask; public class Main extends TimerTask { private DateFormat formatter = new SimpleDateFormat("hh:mm:ss a"); public static void main(String[] args) { TimerTask task = new Main(); Timer timer = new Timer(); timer.scheduleAtFixedRate(task, new Date(), 1000); } public void run() { System.out.println(formatter.format(new Date())); } }