jsカウントダウン機能


//   
function xxx(){
    //  2   ,       ,         。    getTimeOutMix   ,
    //currentTime          ,startTimeStr   xxxx/hh/mm/ss 00:00:00  
    var timeOutMis = getTimeOutMis(currentTime,startTimeStr);
    var serverTimeArray = [];
    serverTimeArray.push(timeOutMis);
    countdown(serverTimeArray);
}
function getTimeOutMis(currentTime,startTimeStr) {
    		
    		var startTime = 0;
    		if(startTimeStr != null || startTimeStr != '') {
    		    // startTimeStr        
    			startTime = Date.parse(new Date(startTimeStr));
    		}
    		
    		console.log(currentTime+ '==' + startTimeStr);
    		console.log(currentTime+ '==' + startTime);
    		
    		var timeVal = startTime - currentTime;
    		
    		console.log(timeVal);
    		
    		return timeVal;
}
    	
    function countdown(time_distance) {
            //var $timer = $(".js_countdown");
           // if ( $timer.size() < 0 || !isArray($timer)) {
            /*
            if ( $timer.size() < 0 || !isArray($timer)) {
                return;
            }
    */
            
            var $timer = $(".js_countdown");
            if ( $timer.size() < 0 || !isArray(time_distance)) {
                return;
            }
            
            $timer.each(function(e) {
                var time_arry = time_distance[e];
                var me = $(this);
                main(time_arry,me); 
            });

            function isArray(obj) {  
                return Object.prototype.toString.call(obj) === '[object Array]';   
            }

            function main(time_arry,elem) {

                if (time_arry >= 0) {
                    var int_day, int_hour, int_minute, int_second;
                    var timeDown = time_arry,timerID;
                    //int_day = Math.floor(timeDown / 86400000);
                    //timeDown -= int_day * 86400000;
                    int_hour = Math.floor(timeDown / 3600000);
                    timeDown -= int_hour * 3600000;
                    int_minute = Math.floor(timeDown / 60000);
                    timeDown -= int_minute * 60000;
                    int_second = Math.floor(timeDown / 1000);

                    //int_day = int_day < 10 ? "0" + int_day : int_day;
                    int_hour = int_hour < 10 ? "0" + int_hour : int_hour;
                    int_minute = int_minute < 10 ? "0" + int_minute : int_minute;
                    int_second = int_second < 10 ? "0" + int_second : int_second;

                    if(int_hour >=999) {
                    	int_hour = 999;
                    }
                     
                     //  , ,      class=count_hour,count_min,count_sec     
                    //elem.find(".day").text(int_day);
                    elem.find(".count_hour").text(int_hour);
                    elem.find(".count_min").text(int_minute);
                    elem.find(".count_sec").text(int_second);

                    //           
                    if (parseInt(int_hour) == 0 && parseInt(int_minute) == 0 && parseInt(int_second) == 0) {
                    	
                        clearTimeout(timerID);
                        return;    
                    }
                    time_arry -= 1000;
                    timerID = setTimeout(function() {
                        main(time_arry,elem);
                    }, 1000);
                } else {
	            	
                    clearTimeout(timerID);
                }
            }
           // main();
        }
簡単に言えば、プロセスは.2時間の時間差を計算します.2時間をミリ秒に変換してから減算します.この結果はカウントダウンの時間です.
そしてこの結果を日、時、分、秒に変換すればいいです.