Hello, I'm messing around with LocalDateTime and I was wondering what method does one has to implement in order to make the timer stop after n times where n is the int the user enters. Also, is it my correct understanding that within 'java.time.LocalDateTime' the 'time' bit is the library, and the LocalDateTime is the class within it? Or is 'time' the package and 'LocalDateTime' the library of classes? I'll paste my program below.
Note: You can just ignore the comments, they're more for me to help me memorize what each part does.
import java.time.format.DateTimeFormatter; import java.util.Timer; import java.util.TimerTask; import java.time.LocalDateTime; public class DisplayingCurrentDateTime extends TimerTask{ public static void main(String[] args) { //This prints out the local date and time ONCE DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd"); LocalDateTime now = LocalDateTime.now(); System.out.println(dtf.format(now)); System.out.println("==============="); //This below outputs the time to console every second (1000ms) Timer timer = new Timer(); timer.schedule(new DisplayingCurrentDateTime(), 0, 1000);// timer.schedule(TimerTask task, long delay, long period) }//end main @Override public void run() { DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm:ss"); LocalDateTime now = LocalDateTime.now(); System.out.println(dtf.format(now)); } }//end class