Whiteship
  • Home
  • 인프런 강의
  • Java
  • Spring
  • JPA
  • SDE Tips
Subscribe

DateTimeFormatter

A collection of 1 post
DateTimeFormatter

DateTimeFormatter 사용할 때 파싱하려는 문자열의 Locale 정보도 꼭 주는게 좋다.

다음과 같이 DateTimeFormatter를 사용해서 “6:55 AM”이라는 문자열을 LocalTime으로 파싱하려고 한다. @Test public void testParsingTime() { String time = "6:55 AM"; LocalTime localTime = LocalTime.parse(time, DateTimeFormatter.ofPattern("h:mm a")); assertThat(localTime.getHour(), is(6)); assertThat(localTime.getMinute(), is(55)); } 코드에는 별로 크게 이상한 점이 보이지 않는다. 파싱하는 패턴이
Mar 10, 2016 — 3 min read
Whiteship © 2022
Powered by Ghost