아래 예제 코드에서 문제가 보이지 않는 것 같습니다. 어떤 이유로 든 올해를 무시하고 날짜가 같다고 말하면서 아래 출력물에서 볼 수 있습니다. 나는 간단한 것을 놓치고 있어야합니다.datetime 변환 Java 문자열 문제
2006년 1월 28일
2007년 1월 16일
화 4월 1일 태평양 서머 타임 00시 00분 0초 2008
화 4월 1일 태평양 서머 타임 00시 00분 0초 2008
수행
import java.util.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
class ExampleProgram {
public static void main(String[] args){
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
String d1String = "01/28/2006";
String d2String = "01/16/2007";
System.out.println(d1String);
System.out.println(d2String);
Date d1=null;
try {
d1 = df.parse(d1String);
} catch (ParseException e) {
System.out.println(e.getMessage());
}
Date d2=null;
try {
d2 = df.parse(d2String);
} catch (ParseException e) {
System.out.println(e.getMessage());
}
System.out.println(d1);
System.out.println(d2);
System.out.println("done");
}
}
만우절 농담? 둘 다 날짜가 모두 4 월 1 일과 일치한다는 것은 매우 복잡한 것 같습니다. + 1 년, -12 개월 == 같은 날짜. dateformat 객체가 strict 인 경우 (df.setLenient (false)) 오류가 발생합니다. – evnafets