?
Solved

A similar function to DateAdd() in javascript

Posted on 2003-03-03
5
Medium Priority
?
386 Views
Last Modified: 2011-09-20
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
0
Comment
Question by:kenadelglass
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 8060466
var d = new Date();

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

alert(d);
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 400 total points
ID: 8060479
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8060673
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8060684
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
 
LVL 1

Author Comment

by:kenadelglass
ID: 8064485
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question