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
}
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 ''
}
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
}
function getDayType(str, connect) {
let valIdx = str.match(/^(\d{4})(\d{1,2})(\d{1,2})/)
let target = valIdx.shift()
let newVal = valIdx.join(connect)
return newVal
}
console.log(getDayType('20200629', '-'))
console