内容引入至网络
<!DOCTYPE html> <html> <head> < http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> < >秒转换为时分秒</ > < src=\"http://code.jquery.com/jquery-1.11.2.js\"></ > </head> <body> <input type=\"text\" id=\"demo1\">s <button id=\"btn\">转换</button> <input type=\"text\" id=\"demo2\">或 <input type=\"text\" id=\"demo3\"> < language=\" \"> /** * 将秒数换成时分秒格式 */ function formatSeconds(value) { var theTime = parseInt(value);// 秒 var theTime1 = 0;// 分 var theTime2 = 0;// 小时 if(theTime > 60) { theTime1 = parseInt(theTime/60); theTime = parseInt(theTime%60); 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 formatSeconds2(a) { var hh = parseInt(a/3600); if(hh<10) hh = \"0\" + hh; var mm = parseInt((a-hh*3600)/60); if(mm<10) mm = \"0\" + mm; var ss = parseInt((a-hh*3600)%60); if(ss<10) ss = \"0\" + ss; var length = hh + \":\" + mm + \":\" + ss; if(a>0){ return length; }else{ return \"NaN\"; } } </ > < > $(\"#btn\").on( \"click\", function( event ) { var x = $(\"#demo1\").val(); var y = formatSeconds(x); $(\"#demo2\").val(y); $(\"#demo3\").val(formatSeconds2(x)); }); </ > </body> </html>
继续阅读与本文标签相同的文章
上一篇 :
详细介绍Spring 5 中的新特性与增强
-
汇编(一) 汇编语言CPU、存储器、指令等概念
2026-05-19栏目: 教程
-
Github开源项目:Tamboot Cloud Admin一个基于spring cloud的微服务脚手架项目
2026-05-19栏目: 教程
-
Docker容器实战(三) - Docker的自我重新定位
2026-05-19栏目: 教程
-
阿里云注册域名使用教程
2026-05-19栏目: 教程
-
Docker容器实战(四) - 纷纷扰扰,终归尘土
2026-05-19栏目: 教程
