import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class Main {
public static void main(String[] args) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd h/mm");
String now = dateTimeFormatter.format(LocalDateTime.now());
System.out.println("현재시간: " +now);
}
}
스파르타코딩클럽 자바 문법 뽀개기 날짜와 시간 다루기 단원의 quiz 코드이다.
DateTimeFormatter newFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
String myDate = newFormatter.format(LocalDate.now());
System.out.println(myDate);
위 코드는 덩어리로 받아들여야 할 듯 하다. ofPattern()에 format을 지정해주어 거기에 현재 날짜/ 시간 값이 입력되도록 하는 것이다.
'WIL(What I Learned)' 카테고리의 다른 글
Week I Learned (0) | 2021.07.11 |
---|---|
TIL (0) | 2021.07.10 |
예외, 에러처리 quiz (0) | 2021.07.09 |
Week I Learned (0) | 2021.07.04 |
항해99 3주차 WIL (0) | 2021.06.27 |