首页 > 解决方案 > 倒计时不超过两个日期

问题描述

需要帮助来自定义此脚本

 <script>
            jQuery(document).ready(function($){             
                $('.demo4').dsCountDown({
                    startDate: new Date("December 11, 2020 12:12:29"),
                    endDate: new Date("December 12, 2020 12:12:29"),
                    theme: '',
                    titleDays: 'd',
                    titleHours: 'h',
                    titleMinutes: 'm',
                    titleSeconds: 's'
                    ,onFinish: function(){ 
                    $.ajax({
            type: 'GET',
            url: 'get_update.php'
            });
            setTimeout(function(){
            window.location = "index.php?go=stake"; 
            }, 3000);
                    }
                });
            });
        </script>   

如何将这两个日期之间的时间更改为单个值

startDate: new Date("December 11, 2020 12:12:29"),
endDate: new Date("December 11, 2020 12:17:29"),

我想要单个值等 5 分钟不在两个日期之间,例如 startdate - enddate

标签: javascriptphpajaxcountdowncountdowntimer

解决方案


var diffMs = (startDate - endDate);
var diffDays = Math.floor(diffMs / 86400000); // days
var diffHrs = Math.floor((diffMs % 86400000) / 3600000); // hours
var diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); // minutes
console.log(diffDays + " days, " + diffHrs + " hours, " + diffMins + " minutes)");

推荐阅读