在javascript中以秒为单位添加时间

时间:2015-11-26 15:49:59

标签: javascript time

我有这个功能

        var countt = count, time = count.data('countdown'), format = count.data('format');
        var Otime = new Date(time), o = {
            serverSync: serverTime,
            until:Otime,
            // demo data set to reset timer, when it's finished
            // change zeroCallback to prefered callback
            zeroCallback: function(options) {
            }
        };
        if(format){
            $.extend(o,{format:format});
        }else{
            $.extend(o,{layout: '{dn} {dl} {hnn}{sep}{mnn}{sep}{snn}'});
        }
        count.countdown(o)
    }

我想为此var Otime = new Date(time)添加10秒 我正在寻找像

这样的东西
var Otime = new Date(time) + 10 seconds

有适当的方法吗?

编辑:

function change_date(count)
    {
        var  serverTime = function() { 
            var time = null; 
            $.ajax({
                url: 'index.php', 
                async: false, 
                dataType: 'text', 
                data:{
                    page:'__request',
                    module:'PSF_auctions',
                    action:'get_server_time'
                },
                success: function(text) { 
                    time = new Date(text); 
                }, 
                error: function(http, message, exc) { 
                    time = new Date(); 
                }
            }); 
            return time; 
        }

这将返回时间变量,即当前系统时间

1 个答案:

答案 0 :(得分:2)

var Otime = new Date(time)
Otime.setSeconds(Otime.getSeconds() + 10);