这是正则的方法var dateStr = '20180418230102'; var reg = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/; dateStr = dateStr.replace(reg, '$1-$2-$3 $4:$5:$6'); "2018-04-18 23:01:02"
这是正则的方法