毫秒数变成时分秒倒计时

js抽象代码:
;(function($){
/**时间间隔对象
 * @author Karajan
 * @param gap 间隔毫秒
 * @param {cT:当前时间(毫秒),eT:截止时间(毫秒),gap:间隔(毫秒),aEven:到点触发的事件function,iEven:初始化函数,初始化时被调用,lEven:倒计时结束触发方法}
 *
 */
    function dateGap(gap){
        var di=[],dCt=[1000*60*60*24,1000*60*60,1000*60,1000,1];
        for(i=0;i<dCt.length;i++){
            di[i]=Math.floor(gap/dCt[i]);gap=gap%dCt[i];
        }
        this.format=function(fmt){
            var o = {"\\$d+":di[0],"\\$h+":di[1],"\\$m+":di[2],"\\$s+":di[3],"\\$S+":di[4]};
            for ( var k in o) {
                if (new RegExp("("+k+")").test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1)?(o[k]):(("00" + o[k]).substr(("" + o[k]).length>2?2:("" + o[k]).length)));
                };
            }
            return fmt;
        }
        this.getD=function(){return di;}
    }
    $.gTimer=function(param){
        var opt={ct:null,et:null,gap:1000,aEven:null,iEven:null,lEven:null,Tindex:null};
        $.extend(opt,param);
        if(opt.ct==null||opt.et==null||opt.aEven==null)return;
        if(opt.iEven)opt.iEven.apply(opt);
        var t=setInterval(function(){
            $.extend(opt,{dt:new dateGap(opt.et-opt.ct)});
            if(opt.ct>=opt.et){opt.ct=opt.et;clearInterval(t);opt.dt=new dateGap(opt.et-opt.ct);if(opt.lEven)opt.lEven.apply(opt);};
            opt.aEven.apply(opt);
            opt.ct=opt.ct+opt.gap;
        },opt.gap);
        return t;
    };
})(jQuery);

页面数据显示的js操作:
 /**
        * @description 根据当前场次的时间戳计算倒计时
        * @method getTime
        * @since 2017-05-17
        * @author Karajan
        */
        getTime: function (){
            var curT = new Number($("#timeCurrent").val() || ‘0‘);
            var endT = new Number($("#timeEnding").val() || ‘0‘);
            var $time = $(".current .timeInfo");
            if(endT != ""){
                if(curT<endT){
                    $.gTimer({
                        ct: curT,
                        et: endT,
                        iEven: function() {},
                        aEven: function() {
                            var hh=this.dt.format("$hh");
                            var mm=this.dt.format("$mm");
                            var ss=this.dt.format("$s");
                           /* 倒计时 */
                            if(hh === "00" && mm === "00" && ss === "00") {
                                $time.html("已结束");
                                window.location.reload();
                            }else {
                                $time.html(hh + ‘:‘ + mm + ‘:‘ + ss);
                                $(".current .end").html("距离结束");
                            }
                        },
                        lEven: function() {}
                    });
                }else{
                }
            }
        },
时间: 2024-08-11 06:06:54

毫秒数变成时分秒倒计时的相关文章

关于时间的操作(Java版)——将毫秒转换为年月日时分秒

第一种方式: import java.util.Calendar; import java.util.TimeZone; public class Test { /** * 将毫秒转换为年月日时分秒 * * @author GaoHuanjie */ public String getYearMonthDayHourMinuteSecond(long timeMillis) { Calendar calendar = Calendar.getInstance(TimeZone.getTimeZo

将毫秒转化成时分秒

//将毫秒转换成时分秒 public string formatLongToTimeStr(long a) { try { int hour = 0; int minute = 0; int second = 0; second = Convert.ToInt32(a) / 1000; if (second > 60) { minute = second / 60; second = second % 60; } if (minute > 60) { hour = minute / 60; m

C#实现毫秒转换成时分秒的方法

本文实例讲述了C#实现毫秒转换成时分秒的方法.分享给大家供大家参考.具体实现方法如下: public static String formatLongToTimeStr(Long l) { String str = ""; int hour = 0; int minute = 0; int second = 0; second = l.intValue() / 1000; if (second > 60) { minute = second / 60; second = seco

js简单时分秒倒计时

最近做浏览器界面倒计时,用js就实现,两种方式: 一:设置时长,进行倒计时.比如考试时间等等 代码如下: 1 <html> 2 <head> 3 <meta charset="UTF-8"> 4 <title>简单时长倒计时</title> 5 <SCRIPT type="text/javascript"> 6 var maxtime = 60 * 60; //一个小时,按秒计算,自己调整! 7

最简时分秒倒计时

代码:单页面 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible&qu

使用CounterDownTimer实现时分秒倒计时

使用android提供的android.os包中的 counterDownTimer可以很方便的实现倒计时功能,具体如下: import android.os.CountDownTimer; public class Couterdown extends CountDownTimer { public Couterdown(long millisInFuture, long countDownInterval) { super(millisInFuture, countDownInterval)

将毫秒数转换为时分秒

主要代码如下 1 public class test { 2 3 public static void main(String[] args) { 4 long ms = 300000; 5 SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");//这里想要只保留分秒可以写成"mm:ss" 6 formatter.setTimeZone(TimeZone.getTimeZone("GMT

PHP 秒数 转时分秒 函数

function secondsToHour($seconds){ if(intval($seconds) < 60) $tt ="00时00分".sprintf("%02d",intval($seconds%60)); if(intval($seconds) >=60){ $h =sprintf("%02d",intval($seconds/60)); $s =sprintf("%02d",intval($sec

javascript 简单时分秒倒计时

<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <title>Title</title> <style> .time_box { width: 200px; height: 50px; margin: 50px auto; } .time_box div { float: left; width: 3