这是完整的代码以及最后的答案(为了更加清晰).
在您的data-config.xml文件中,从DB读取日期并转换为时间戳:
select cast(STRT_DT as timestamp) as STRT_DTTS from DATES
放入DataImportHandler实体,如下所示:
query="select cast(STRT_DT as timestamp) as STRT_DTTS from DATES" >
此查询将返回oracle.sql.TIMESTAMP,但它不会直接映射到日期.因此需要脚本转换器.因此我们引入脚本:startDateTransform.在相同的data-config.xml中,您可以像这样插入JavaScript:
function startDateTransform(row){
// Get the timestamp and convert it to a date
var dateVal = row.get("STRT_DTTS").dateValue();
// Put the correct date object into the original column
row.put("STRT_DTTS", dateVal);
return row;
}
在这里,我们将时间戳转换为日期,更新列值并返回包含新信息的行.
字段STRT_DT:
现在应该包含正确的日期.