后台返回时间格式 20190825 1439 前端需要展示为2019-08-25 14:39

310 阅读1分钟
function handleYear(time) {
    if (!time) {
        return
    }
    let arr = [];
    let str1 = time.substr(0, 4)
    let str2 = time.substr(4, 2)
    let str3 = time.substr(6)
    arr.push(str1, str2, str3)
    return arr.join('-')
}

console.log(handleYear('20190825'), 'hello');

function handleDay(time) {
    if (!time) {
        return
    }
    let arr = [];
    let str1 = time.substr(0, 2)
    let str2 = time.substr(2)
    arr.push(str1, str2)
    return arr.join(':')
}
console.log(handleDay('0825'), 'helloworld');