我试图将域日期转换为java util date,但它失败了。我正在使用该方法进行转换:
public static java.util.Date convertDomainDateToUtilDate(oracle.jbo.domain.Date domainDate) {
java.util.Date date = null;
if (domainDate != null) {
java.sql.Date sqldate = domainDate.dateValue();
date = new Date(sqldate.getTime());
}
return date;
}
使用getValue
直接获得正确的类型
public static java.util.Date convertDomainDateToUtilDate(oracle.jbo.domain.Date domainDate) {
if (domainDate != null) {
return domainDate.getValue();
}
return null;
}
或者如果你想转移到Java 8 LocalDate
public static LocalDate convertDomainDateToUtilDate(oracle.jbo.domain.Date domainDate) {
if (domainDate != null) {
return domainDate.getValue().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
}
return null;
}
根据@ OleV.V的推荐,您还可以从java.sql.Date获取LocalDate
public static LocalDate convertDomainDateToUtilDate(oracle.jbo.domain.Date domainDate) {
if (domainDate != null) {
return domainDate.dateValue().toLocalDate();
}
return null;
}