Javascript countdown for specific time and date

后端 未结 3 1690
傲寒
傲寒 2020-12-29 17:41

I am using a jQuery plugin to put the countdown timer in my webpage. Currently the code that controls what the timer displays is:



        
3条回答
  •  抹茶落季
    2020-12-29 18:00

    I'm asssuming the first arg of .FlipClip() is the amount of time until the countdown completes. This time, "t", should be the difference between now and the target time.

    var t = targetTimeInMs - currentTimeInMs;
    

    To get the current time, use the no-arg Date constructor.

    var currentTimeInMs = new Date().getTime();
    

    To get the target time, supply Date with arguments. Here are a few examples from MDN:

    var today = new Date();
    var birthday = new Date("December 17, 1995 03:24:00");
    var birthday = new Date(1995,11,17);
    var birthday = new Date(1995,11,17,3,24,0);
    

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

    I'm not exactly sure if you need to supply milliseconds as the first arg to your .FlipClip() function. Consult the documentation/source for that. Then use the appropriate method of the Date object to get the required unit (seconds? minutes? hours? and use date.getSeconds(), getHours(), etc, see MDN.)

提交回复
热议问题