当我使用下面的函数时,它成功返回的唯一时间是我只对单个字符串使用它。如果我尝试在代码中针对不同的唯一字符串多次调用该函数,则会返回"不可解析的日期"错误。
function oraDate(str) {
if(str.length > 0){
channelMap.put("StringCount", str.length);
if(str.length == 8){
channelMap.put("8 characters", "Date only");
var date = str.substring(0, 8);
var cDate = DateUtil.convertDate("yyyyMMdd", "yyyy-MM-dd", date);
return cDate + 'T' + '00:00:00';
} else if(str.length == 12){
channelMap.put("12 characters", "Date/time only");
var date = str.substring(0, 8);
var time = str.substring(8, 12);
var cDate = DateUtil.convertDate("yyyyMMddHHmm", "yyyy-MM-dd'T'HH:mm", date);
return cDate+':00';
} else if(str.length >= 14){
channelMap.put("14 characters", "Date/time w/seconds only");
var date = str.substring(0, 8);
var time = str.substring(8, 14);
var date_time = date+time;
var cDate = DateUtil.convertDate("yyyyMMddHHmmss", "yyyy-MM-dd'T'HH:mm:ss", date_time);
return cDate;
}
} else {
return '0001-01-01T00:00:00';
}
}
答案 0 :(得分:0)
我忘了回到这里发布修复。我错过了" date_time" 12个字符检查的变量。
function oraDate(str) {
if(str.length > 0){
channelMap.put("StringCount", str.length);
if(str.length == 8){
channelMap.put("8 characters", "Date only");
var date = str.substring(0, 8);
var cDate = DateUtil.convertDate("yyyyMMdd", "yyyy-MM-dd", date);
return cDate + 'T' + '00:00:00';
} else if(str.length == 12){
channelMap.put("12 characters", "Date/time only");
var date = str.substring(0, 8);
var time = str.substring(8, 12);
var date_time = date+time;
var cDate = DateUtil.convertDate("yyyyMMddHHmm", "yyyy-MM-dd'T'HH:mm", date_time);
return cDate+':00';
} else if(str.length >= 14){
channelMap.put("14 characters", "Date/time w/seconds only");
var date = str.substring(0, 8);
var time = str.substring(8, 14);
var date_time = date+time;
var cDate = DateUtil.convertDate("yyyyMMddHHmmss", "yyyy-MM-dd'T'HH:mm:ss", date_time);
return cDate;
}
} else {
return '0001-01-01T00:00:00';
}
}