If this function is passed an invalid date and is called IllegalFieldValueExcption, I would like to return the default date 0001-01-01. But when the code below is run, the date created in defaultDateis equal 0001-01-02, which is incorrect. Does anyone see something that I am doing wrong?
public Date unmarshal(String string) {
DateTimeFormatter fmt = new DateTimeFormatter(null, DateTimeFormat.forPattern("yyyy-MM-dd").getParser());
Date defaultDate = DateTime.parse("0001-01-01", fmt).toDate();
try {
return formatter.parseDateTime(string).toDate();
}
catch (IllegalFieldValueException e) {
return defaultDate;
}
}
EDIT:
I updated the first two lines and now it works great, thanks!
Chronology chrono = GJChronology.getInstance();
Date defaultDate = new DateTime(0001, 01, 01, 10, 0, 0, 0, chrono).toDate();
source
share