javascript秒数変換時分秒

1058 ワード

jsは時間分秒に変換する方法を説明する.    
       function formatSeconds(value) {
	        var secondTime = parseInt(value);//  
	        var minuteTime = 0;//  
	        var hourTime = 0;//   
	        if(secondTime > 60) {//      60,        
	            //    ,  60   ,      
	            minuteTime = parseInt(secondTime / 60);
	            //    ,    ,      
	            secondTime = parseInt(secondTime % 60);
	            //      60,        
	            if(minuteTime > 60) {
	                //    ,      60,      
	                hourTime = parseInt(minuteTime / 60);
	                //         ,      60    
	                minuteTime = parseInt(minuteTime % 60);
	            }
	        }
	        var result = "" + parseInt(secondTime) + " ";

	        if(minuteTime > 0) {
	        	result = "" + parseInt(minuteTime) + " " + result;
	        }
	        if(hourTime > 0) {
	        	result = "" + parseInt(hourTime) + "  " + result;
	        }
	        return result;
	    }