람다식으로 1초마다 시간 출력(Runnable 이용)
0.사용할 시간 클래스
LocalDateTime(시각.now()), DateTimeFormatter(표현형식 만들기.ofPattern())
public class Test02_day18 {
public static void main(String[] args) {
//1.익명의 내부클래스
Runnable r = new Runnable() {
@Override
public void run() {
}
};
//2. 람다식
new Thread(()->{
}).start();
}
}
public class Test02_day18 {
public static void main(String[] args) {
//1.익명의 내부클래스
Runnable r = new Runnable() {
@Override
public void run() {
while(true) {
LocalDateTime lt = LocalDateTime.now();
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-mm-dd HH:mm:ss");
String time = lt.format(df);
System.out.println("현재시각: "+time);
try {
Thread.sleep(1000);
}catch(InterruptedException ie) {
System.out.println(ie.getMessage());
}
}
}
};
new Thread(r).start();
//2. 람다식
new Thread(()->{
while(true) {
LocalDateTime lt = LocalDateTime.now();
DateTimeFormatter df = DateTimeFormatter.ofPattern("yy년 mm월 dd일 hh시 mm분 ss초");
String time= lt.format(df);
System.out.println("지금은 "+time+"입니다.");
try {
Thread.sleep(1000);
}catch(InterruptedException ie) {
System.out.println(ie.getMessage());
}
}
}).start();
}
}