//为字符串插入字符 其中soure为原字符串,start为将要插入字符的位置,newStr为要插入的字符
function insertStr(soure, start, newStr){
return soure.slice(0, start) + newStr + soure.slice(start);
}
示例:
var occurTime = 201806042313; //原字符串
var _NewOccurTime = insertStr(insertStr(insertStr(insertStr(insertStr(occurTime,4,"/"),7,"/"),10," "),14,":"),17,":00");
alert(_NewOccurTime ); //2018/06/04 23:13:00
function insertStr(soure, start, newStr){
return soure.slice(0, start) + newStr + soure.slice(start);
}