0
문자열 패턴에 지정된 연도 (및 다른 여러 시간 필드) 만 지정하면 다른 부재 필드가 가장 낮은 값으로 설정됩니다. 예를 들어, 이전에 자바 8에 내 코드가 java.time
포맷에서, 2015.01.01 00:00:00 GMT
Java 8은 모든 필드를 포함하지 않는 문자열에서 ZonedDateTime을 구문 분석합니다.
그러나 저를 반환
String source = "2015";
String pattern = "yyyy";
DateFormat sdf = new SimpleDateFormat(pattern);
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = null;
try {
date = sdf.parse(source);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat sdfGMT2 = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss z");
sdfGMT2.setTimeZone(TimeZone.getTimeZone("GMT"));
String newf = sdfGMT2.format(date);
System.out.println(newf);
처럼 보였다는 TemporalAccessor
반환 내가 나이가 API했던 것처럼
java.time.format.DateTimeParseException: Text '2008' could not be parsed: Unable to obtain ZonedDateTime from TemporalAccessor: {WeekBasedYear[WeekFields[SUNDAY,1]]=2008},ISO of type java.time.format.Parsed
이 어떻게 자바 8 시간 API와 동일한 결과를 얻을 않습니다 : 아래의 코드는 예외를
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("YYYY");
ZonedDateTime zonedDateTime = ZonedDateTime.parse("2008", fmt);
예외를 throw?
내가 '.appendPattern ("YYYY")'이어야합니까? – Antonio
그게'appendValue()'가 위에서 무엇을하는지입니다. 그러나 appendPattern()을 사용하려면 [yyyy'] (http://docs.oracle.com/javase/8/docs/api/java/time/temporal/ChronoField.html#YEAR)를 사용해야합니다. ['YYYY' 대신] (http://docs.oracle.com/javase/8/docs/api/java/time/temporal/WeekFields.html#weekBasedYear--) –
예, 'YYYY'는 예외를 발생시킵니다. 고마워, 그게 도움이 됐어! 별도의 스레드에서 다른 질문을하고 나에게 도움을 환영합니다 :) – Antonio