|
-
May 21st, 2003, 11:30 PM
#1
Thread Starter
Frenzied Member
Javascript: how do I add seconds to a date? [resolved]
how do I add seconds to a date?
I'm just starting to work with Javascript but I need this pretty fast.
I need to design a Javascript function that works something like VB's dateadd() function.
It only needs to do seconds so it would look something like this:
function addSeconds(myDate, Seconds)
{
//Needed Code...newDate = myDate + Seconds;
return newDate;
}
Alternately, a function that just adds xx seconds to the current date will work.
function DatePlusSecs(Seconds)
{
var myDate = new Date();
//Needed Code....newDate = myDate + Seconds;
return newDate;
}
I've been searching web sites for this but haven't found anything that i could understand/make work.
Last edited by longwolf; May 27th, 2003 at 05:47 PM.
-
May 25th, 2003, 09:32 PM
#2
Fanatic Member
I'm not really familiar with VB's addDate() function.
Could you specify the date format you are using? Is it a string? Is your date a number in minutes?
ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet? 
-
May 25th, 2003, 11:47 PM
#3
Thread Starter
Frenzied Member
I'm using:
myDate = new Date();
as part of a timer loop.
I need to add XX seconds to myDate so I can use:
if (Date() > myDate) {}
to trigger an action.
I'd like to be able to display myDate to the user in a format that makes sense to them. i.e. date and time
Last edited by longwolf; May 25th, 2003 at 11:59 PM.
-
May 26th, 2003, 02:18 AM
#4
To trigger a delayed action use setTimeout().
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 26th, 2003, 04:33 AM
#5
Thread Starter
Frenzied Member
I guess I need to make things a bit more clear.
I writing a fairly complex program with javascript.
There is a main loop that can call several subs depending on what happens.
Some of those sub-functions must not run too often.
That's why I need be able to add xx seconds to a variable that holds a date for testing against Date().
I also need to be able to pull up that date variable and look at it.
This is actually a script that's followed by a C++ program.
I did try using setTimeout() to controll a flag, but the C++ app gave me "setTimeout is not defined"
But that command would not have given me all that I need anyway
-
May 26th, 2003, 09:42 AM
#6
This is actually a script that's followed by a C++ program.
What do you mean by that? Who interprets the JavaScript?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 27th, 2003, 12:43 AM
#7
Thread Starter
Frenzied Member
Originally posted by CornedBee
What do you mean by that? Who interprets the JavaScript?
I worded that badly.
It's part of a macro-ing program.
The C++ app is a "go-between" program.
It tracks and interprets what's happening in a 3rd program and can send commands to the 3rd program.
It has it's own function calls that the Javascript uses to get values from the 3rd program and more functions to tell the C++ app which commands to send to the 3rd program.
It also has some error checking that it uses to tell you when it finds an error in your Javascript.
I don't have the source code for the C++ app (wish I did) so I can't tell you any more about it.
Here's the silly part. Like I said, I'm new to Javascript and at this point I know more of the C++ app's function calls than I know of Javascript functions : D
That's why I'm asking someone to show me how to "add xx seconds to a date variable"
-
May 27th, 2003, 04:59 AM
#8
devedge.netscape.com has a complete JavaScript reference somewhere.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 27th, 2003, 07:51 AM
#9
Thread Starter
Frenzied Member
Originally posted by longwilf
I've been searching web sites for this but haven't found anything that i could understand/make work.
I've been studying a Lot of tutorial sites.
-
May 27th, 2003, 09:23 AM
#10
devedge is a reference, not a tutorial.
Quite easy to figure out after reading a bit and trying a bit:
Code:
function addSecs(d, s) {
return new Date(d.valueOf()+s*1000);
}
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 27th, 2003, 05:44 PM
#11
Thread Starter
Frenzied Member
Originally posted by CornedBee
devedge is a reference, not a tutorial.
Quite easy to figure out after reading a bit and trying a bit:
Code:
function addSecs(d, s) {
return new Date(d.valueOf()+s*1000);
}
Easy for you maybe : )
From the sites I looked at it seemed like I'd have to build the a date step at a time.
This is GREAT!
Thx CornedBee
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|