250x250
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Eclipse
- jpa
- ubuntu
- error
- myBatis
- Tomcat
- MySQL
- JDBC
- 문서
- Source
- Docker
- 설정
- Thymeleaf
- oracle
- JavaScript
- PostgreSQL
- IntelliJ
- 오픈소스
- git
- Open Source
- Python
- maven
- spring
- STS
- AJAX
- SpringBoot
- Core Java
- MSSQL
- Spring Boot
- Exception
Archives
- Today
- Total
헤르메스 LIFE
[Exception] java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: HourOfDay 본문
Exception
[Exception] java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: HourOfDay
헤르메스의날개 2020. 12. 29. 13:32728x90
getDateTimeFormat( "yyyyMMddHHmmssfff" ) 를 사용해서 함수롤 Call 했더니 아래와 같은 오류가 발생했습니다.
Exception in thread "main" java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: HourOfDay at java.time.LocalDate.get0(LocalDate.java:680)at java.time.LocalDate.getLong(LocalDate.java:659) at java.time.format.DateTimePrintContext.getValue(DateTimePrintContext.java:298) at java.time.format.DateTimeFormatterBuilder$NumberPrinterParser.format(DateTimeFormatterBuilder.java:2540) at java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(DateTimeFormatterBuilder.java:2179) at java.time.format.DateTimeFormatter.formatTo(DateTimeFormatter.java:1746) at java.time.format.DateTimeFormatter.format(DateTimeFormatter.java:1720) at java.time.LocalDate.format(LocalDate.java:1691) at sample.DateSample.getDateTimeFormat(DateSample.java:27) at sample.DateSample.main(DateSample.java:14) |
원인은 LocalDate Class 였습니다.
LocalDate 는 날짜만을 생성하는 Class 입니다.
날짜 + 시간 을 생성하기 위해서는 LocalDateTime 을 사용해야 합니다.
public static String getDateTimeFormat( String dateFormat ) {
LocalDate nowDate = LocalDate.now();
DateTimeFormatter formatter = null;
String strDate = "";
try {
formatter = DateTimeFormatter.ofPattern( dateFormat );
} catch ( Exception e ) {
formatter = DateTimeFormatter.ofPattern( "yyyyMMddHHmmss" );
}
strDate = nowDate.format( formatter );
return strDate;
}
public static String getDateTimeFormat( String dateFormat ) {
LocalDateTime nowDate = LocalDateTime.now();
DateTimeFormatter formatter = null;
String strDate = "";
try {
formatter = DateTimeFormatter.ofPattern( dateFormat );
} catch ( Exception e ) {
formatter = DateTimeFormatter.ofPattern( "yyyyMMddHHmmss" );
}
strDate = nowDate.format( formatter );
return strDate;
}
728x90