字符串转化为日期格式,用正则能快速转化
''20200101''match(/(\d{4})(\d{2})(\d{2})/).filter((item,index) => index > 0).join('-')
第二种方法,比较复杂
a = []
a.push(''20200101''.slice(0,4),''20200101''.slice(4,6),"20200101".slice(6))
console.log( a ) // [ ''2020'' , ''01'', '' 01'' ]
a.join( '' - '')
console.log( ''2020-01-01'' )
网友评论