SOURCE

// 格式化时间

function formatDate(date, fmt) {
    if (!date) {
        return ''
    }
    date = new Date(date)
    fmt = fmt || 'yyyy-MM-dd hh:mm:ss'
    let o = {
        'M+': date.getMonth() + 1, //月份
        'd+': date.getDate(), //日
        'h+': date.getHours(), //小时
        'm+': date.getMinutes(), //分
        's+': date.getSeconds(), //秒
        'q+': Math.floor((date.getMonth() + 3) / 3), //季度
        S: date.getMilliseconds(), //毫秒
    }
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
    for (let k in o)
        if (new RegExp('(' + k + ')').test(fmt))
            fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length))
    return fmt
}
// console.log(formatDate(1592552929000))
// console.log(formatDate(120050))

function dateFormatter(row) {
    let datetime = row;
    if (datetime) {
        datetime = new Date(datetime);
        let y = datetime.getFullYear() + '-';
        let mon = datetime.getMonth() + 1 + '-';
        let d = datetime.getDate();
        return y + mon + d;
    }
    return ''
}
// console.log(dateFormatter(1592552929000))

function getDay(str) {
    let valIdx = str.match(/^(\d{4})(\d{1,2})(\d{1,2})/)
    let newVal = `${valIdx[1]} - ${valIdx[2]} - ${valIdx[3]}` 
    return newVal
}
// console.log(getDay('20200629'))

function getDayType(str, connect) {
    let valIdx = str.match(/^(\d{4})(\d{1,2})(\d{1,2})/)
    let target = valIdx.shift()
    // console.log(target, valIdx)
    let newVal = valIdx.join(connect) 
    return newVal
}
// getDayType('20200629')
console.log(getDayType('20200629', '-'))
console 命令行工具 X clear

                    
>
console