从字符串中获取时间格式的字符

const list = 'ddsadsd2012-02-09 19:00'
for (let i = 0; i < list.length; i++) {
let str = list[i].workContent
console.log('str',str)
let datetime = [], date;
str.replace(/((\d{4}(-\d{1,2}){2}).{2})?(\d{1,2}(:\d{1,2}){2})/g, function ($0, $1, $2, $3, $4) {
if ($2 && $2 !== date) date = $2;
datetime.push($1+$4);
})
list[i].time=datetime[0]?datetime[0]:''
console.log('time',datetime.join('\n'))
}
posted on 2020-02-10 17:05  IT tt  阅读(647)  评论(0编辑  收藏  举报