例如08分鐘50秒16分鐘02秒這樣的如何轉換為秒啊?
有大佬遇到過這個問題嗎:如何將帶有漢字的時間轉換出秒?求指導!
藍山帝景
2019-06-09 11:43:46
TA貢獻1859條經(jīng)驗 獲得超6個贊
varstr='08分鐘50秒';functionchangeSecond(str){returnparseInt(str.split(/分鐘|秒/)[0]*60)+parseInt(str.split(/分鐘|秒/)[1]);}console.log(changeSecond(str))
TA貢獻1772條經(jīng)驗 獲得超5個贊
'2鐘02秒'.match(/(\d+)/g).reverse().reduce((sum,item,i)=>sum+(Math.pow(60,i)*parseInt(item)),0)//122'03小時02鐘02秒'.match(/(\d+)/g).reverse().reduce((sum,item,i)=>sum+(Math.pow(60,i)*parseInt(item)),0)//10922
舉報