How to add 30 minutes to a JavaScript Date object?

前端 未结 20 3305
醉酒成梦
醉酒成梦 2020-11-21 23:21

I\'d like to get a Date object which is 30 minutes later than another Date object. How do I do it with JavaScript?

20条回答
  •  滥情空心
    2020-11-22 00:17

    I feel many of the answers here are lacking a creative component, very much needed for time travel computations. I present my solution for a temporal translation of 30 minutes.

    (jsfiddle here)

    function fluxCapacitor(n) {
        var delta,sigma=0,beta="ge";
        (function(K,z){
    
            (function(a,b,c){
                beta=beta+"tT";
                switch(b.shift()) {
                    case'3':return z('0',a,c,b.shift(),1);
                    case'0':return z('3',a,c,b.pop());
                    case'5':return z('2',a,c,b[0],1);
                    case'1':return z('4',a,c,b.shift());
                    case'2':return z('5',a,c,b.pop());
                    case'4':return z('1',a,c,b.pop(),1);
                }
            })(K.pop(),K.pop().split(''),K.pop());
        })(n.toString().split(':'),function(b,a,c,b1,gamma){
           delta=[c,b+b1,a];sigma+=gamma?3600000:0; 
           beta=beta+"im";
        });
        beta=beta+"e";
        return new Date (sigma+(new Date( delta.join(':')))[beta]());
    }
    

提交回复
热议问题