function format(time) { if(String(time).indexOf('分钟') >= 0) { let time1 = time.slice(0,time.length-1).replace('分钟',':') return time1.split(':')[0].padStart(2,'0')+":"+time1.split(':')[1].padStart(2,'0') }else { return "00:"+time.split('秒')[0].padStart(2,'0') } } console.log(format('10分钟10秒')) console.log(format('20秒'))