A similar function to DateAdd() in javascript

Hi,

I am looking for the javascript equivalent of the Visual Basic DateAdd function...anyone have any code that can continuously add 30 seconds to the date/time?

Thx
LVL 1
kenadelglassAsked:
Who is Participating?
 
knightEknightConnect With a Mentor Commented:
and I'm not sure what you mean by "continuously".  If you want the date object to reflect a date/time that is 30 seconds ahead of the client system's date/time, then AFTER you create the date object with the code above, then do this:

setInterval('d.setSeconds( d.getSeconds()+1 )',1000);
0
 
knightEknightCommented:
var d = new Date();

d.setSeconds( d.getSeconds()+30 );

alert(d);
0
 
fritz_the_blankCommented:
A different approach:

function plus30(){
var datNow = new Date();
var intNow = Date.parse(datNow):
var intPlus30 = intNow + 30*1000:
var datPlus30 = new Date(intPlus30):
return datPlus30
}

Fritz the Blank
0
 
fritz_the_blankCommented:
Sorry, I had colons rather than semicolons on the end:

function plus30(){
     var datNow = new Date();
     var intNow = Date.parse(datNow);
     var intPlus30 = intNow + 30*1000;
     var datPlus30 = new Date(intPlus30);
     return datPlus30
}


Fritz the Blank
0
 
kenadelglassAuthor Commented:
Thank you - I am now headed in the right direction...Actually all I needed was a routine that would run every 30 seconds and setInterval will do the trick...

Thanks again knightEknight
0
All Courses

From novice to tech pro — start learning today.