js将变态的时间格式(X'Y")转为秒

function timeFormatting(strO){ var $h, $m, $s , $time; function partitionArr(strO){ var strA; var ArrCont = new Array(); for( var i= 0; i < strO.length ; i++){ $h = $m = $s = ""; strA = strO[i]; degree(strA); ArrCont.push($h + $m + $s) } return ArrCont; } function degree(A){ var strA = A.split("°"); /*这里的"°",可以根据自己需求切换*/ if( strA.length == 1){ $h = 0 ; minute(strA[0]); }else { $h = strA[0] * 60 * 60 ; /*将小时转化为秒*/ minute(strA[1]); } } function minute(B){ var strB = B.split("′"); if( strB.length == 1){ $m = 0 ; second(strB[0]); }else { $m = strB[0] * 60 ; second(strB[1]); } } function second(C){ var strC = C.split("″"); $s = strC[0] * 1; } if(strO instanceof Array){ $time = partitionArr(strO) }else { degree(strO); $time = $h + $m + $s ; } console.log($time) return $time; }//例: //var testTime = '43°30′25″' //var testTime = ["22°28′36″", "43°32′13″", "23°239′48″", "53°58′46″", "76°90′18″"] var testTime = ["80″", "72″", "84″", "119″", "121″"]timeFormatting(testTime); // 基础的方法,忘大牛指点

    推荐阅读