1final long startTime = System.currentTimeMillis();
2for (int i = 0; i < length; i++) {
3 // Do something
4}
5final long endTime = System.currentTimeMillis();
6
7System.out.println("Total execution time: " + (endTime - startTime));
1import java.time.format.DateTimeFormatter;
2import java.time.LocalDateTime;
3public class CurrentDateTimeExample1 {
4 public static void main(String[] args) {
5 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
6 LocalDateTime now = LocalDateTime.now();
7 System.out.println(dtf.format(now));
8 }
9}
10
1import java.time.LocalTime; // import the LocalTime class
2...
3// To display the current time (hour, minute, second, and nanoseconds)
4LocalTime time = LocalTime.now();
5System.out.println(time); // 11:04:57.416546