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 |
Tags
- AJAX
- IntelliJ
- Python
- MSSQL
- oracle
- Exception
- spring
- Core Java
- SpringBoot
- JavaScript
- jpa
- git
- MySQL
- ubuntu
- STS
- Source
- Tomcat
- Open Source
- myBatis
- Spring Boot
- Eclipse
- error
- Docker
- 오픈소스
- maven
- JDBC
- 설정
- Thymeleaf
- 문서
- PostgreSQL
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