새로운 날짜 시간 API를 사용하여 날짜를 포맷하지만 실행할 때이 :나는 새 날짜 시간 API와 함께 연주했다
public class Test {
public static void main(String[] args){
String dateFormatted = LocalDate.now()
.format(DateTimeFormatter
.ofPattern("yyyy-MM-dd HH:mm:ss"));
System.out.println(dateFormatted);
}
}
이 발생합니다 :
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:2543)
at java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(DateTimeFormatterBuilder.java:2182)
at java.time.format.DateTimeFormatter.formatTo(DateTimeFormatter.java:1745)
at java.time.format.DateTimeFormatter.format(DateTimeFormatter.java:1719)
at java.time.LocalDate.format(LocalDate.java:1685)
at Test.main(Test.java:23)
가의 소스 코드를 볼 때 LOCALDATE 클래스, 나는 참조 :
0 :private int get0(TemporalField field) {
switch ((ChronoField) field) {
case DAY_OF_WEEK: return getDayOfWeek().getValue();
case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((day - 1) % 7) + 1;
case ALIGNED_DAY_OF_WEEK_IN_YEAR: return ((getDayOfYear() - 1) % 7) + 1;
case DAY_OF_MONTH: return day;
case DAY_OF_YEAR: return getDayOfYear();
case EPOCH_DAY: throw new UnsupportedTemporalTypeException("Invalid field 'EpochDay' for get() method, use getLong() instead");
case ALIGNED_WEEK_OF_MONTH: return ((day - 1)/7) + 1;
case ALIGNED_WEEK_OF_YEAR: return ((getDayOfYear() - 1)/7) + 1;
case MONTH_OF_YEAR: return month;
case PROLEPTIC_MONTH: throw new UnsupportedTemporalTypeException("Invalid field 'ProlepticMonth' for get() method, use getLong() instead");
case YEAR_OF_ERA: return (year >= 1 ? year : 1 - year);
case YEAR: return year;
case ERA: return (year >= 1 ? 1 : 0);
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
는 문서에 설명 된대로
이 메서드는 클래스 설명서에 설명 된대로 문자 및 기호의 간단한 패턴을 기반으로 포맷터를 만듭니다.
이 글자는 모두 defined입니다.
그렇다면 왜 DateTimeFormatter.ofPattern
으로 패턴 문자를 사용할 수 없습니까?
https://en.wiktionary.org/wiki/eierlegende_Wollmilchsau (말 그대로 "달걀 양모 - 우유 - 암 s지") 긍정적 인 특성을 지녔거나 가지고 있다고 주장하는 올인원 장치 또는 사람 몇 가지 특수 도구의 작업을 수행 할 수 있습니다. :-) –