<html>
<body>
<p>
<script>
function formatSeconds(value) {
var theTime = parseInt(value);// 秒
var theTime1 = 0;// 分
var theTime2 = 0;// 小时
// alert(theTime);
if(theTime > 60) {
theTime1 = parseInt(theTime/60);
theTime = parseInt(theTime%60);
// alert(theTime1+"-"+theTime);
if(theTime1 > 60) {
theTime2 = parseInt(theTime1/60);
theTime1 = parseInt(theTime1%60);
}
}
var result = ""+parseInt(theTime)+"秒";
if(theTime1 > 0) {
result = ""+parseInt(theTime1)+"分"+result;
}
if(theTime2 > 0) {
result = ""+parseInt(theTime2)+"小时"+result;
}
return result;
}
function formatHMStoS(value){
var h = value.split("小时")[0];
var m = value.split("小时")[1].split('分')[0];
var s = value.split("小时")[1].split('分')[1].split('秒')[0];
var ss= h*60*60+m*60+s;
return ss;
}
function a(value){
document.getElementById("tar").value=formatSeconds(value);
}
function b(value){
document.getElementById("tar2").value=formatHMStoS(value);
}
</script>
秒:
<input id=ss value=""/>
<input type="button" value="秒 转换 时分秒" onClick="a(document.getElementById('ss').value)"/>
<input type="text" id="tar"/>
</p>
<p>
<input id=hms value="12小时43分54秒"/>
<input type="button" value="时分秒 转换 秒" onClick="b(document.getElementById('hms').value)"/>
<input type="text" id="tar2"/>
</p>
</body>
</html>
时分秒转秒,秒转时分秒
猜你喜欢
转载自lncdzh.iteye.com/blog/2301217
今日推荐
周排行