Written by
java-style
on
on
[자바]13. 자바의 최신버전 날짜 패턴화(JDK 1.8~)
[자바]13. 자바의 최신버전 날짜 패턴화(JDK 1.8~)
1.DateTimeFormatter 를 이용하여 패턴화 시키자!
SimpleDateFormat 클래스 보다 최신버전으로서 jdk 1.8 에서 제공하고있다.
2.LocalDate
jdk 1.8 에서는 날짜 정보를 제공하는 api가 추가로 제공되고있다. 왠만하면 이걸 주로 사용하자
import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; public class date { public static void main(String[] args) { LocalDate date = LocalDate.parse("2021-10-03"); System.out.println(date); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("uuuuMMdd"); String test = "19961230"; LocalDate myBirth = LocalDate.parse(test,dateTimeFormatter); System.out.println("myBirth = " + myBirth); } }
2021-10-03 myBirth = 1996-12-30
from http://pulpul8282.tistory.com/199 by ccl(A) rewrite - 2021-10-04 06:02:04