473,378 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

easy for you! - how do I add 5 seconds to date?

FN
I'm new to javascript and internet research is turning up weird things. I
just want to add 5 seconds to a date value.

this = new date() // I believe this sets the time, too, right?

//now how do I add 5 seconds or even 5000 seconds to the variable 'this'?


Jul 20 '05 #1
2 34068
"FN" <ne**************@DELETECAPSyahoo.com> writes:
I'm new to javascript and internet research is turning up weird things. I
just want to add 5 seconds to a date value.

this = new date() // I believe this sets the time, too, right?
Syntax error. The word "this" is a keyword and cannot be used as a variable
name. Also, the date constructor is called "Date" with a capital "D".

So, let's say you have:

var now = new Date();
//now how do I add 5 seconds or even 5000 seconds to the variable 'this'?


now.setSeconds(now.getSeconds() + 5);

For anything you'll ever want to know about dates in Javascript, and
then some, check: <URL:http://www.merlyn.demon.co.uk/js-dates.htm>.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
JRS: In article <d6**********@hotpop.com>, seen in
news:comp.lang.javascript, Lasse Reichstein Nielsen <lr*@hotpop.com>
posted at Fri, 11 Jul 2003 02:11:40 :-
"FN" <ne**************@DELETECAPSyahoo.com> writes:
I'm new to javascript and internet research is turning up weird things. I
just want to add 5 seconds to a date value.
now.setSeconds(now.getSeconds() + 5);


Or
now.setTime(now.getTime() + 5000)

I would use the former if thinking of clock time, and the latter if
thinking of scientific time; but the two will be fully interchangeable,
at least until the software understands Leap Seconds (and that will
destroy many otherwise good algorithms).
There is one minor trap.

If I add 5 seconds to the value of a Date Object, it then represents a
moment undoubtedly 5 seconds later.

But the following code

now = new Date('2003/03/30 01:59:59')
S = now.toLocaleString()
now.setSeconds(now.getSeconds() + 5);
S += ' # ' + now.toLocaleString()

gives me

03/30/2003 01:59:59 # 03/30/2003 01:00:04

which illustrates no fewer than two errors and a possible surprise.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Need Top Programmer | last post by:
Has anyone else encountered this issue? When you do Date.parse(date1) and date1=10/29/2001 it seems to add an an additional 3600000 ms for no reason. Thanks, Edward
5
by: Macca | last post by:
Hi, I have a table which has a date/time field. I am storing them as follows :- 01/01/2005 11:25 01/01/2005 19:44 02/01/2005 05:04
4
by: yer darn tootin | last post by:
Does anyone know the sort expression for a column that's data has been returned in the format, eg '07 Jul 05'?? The sort expression {..:"dd mmm yy"} doesn't work ( if the column was returned as...
16
by: Atley | last post by:
I am trying to get a overall difference on two dates, I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, Seconds, no problems... What I cannot seem to figure out is how to...
1
by: melanieab | last post by:
Hi, If there's a textbox and the text entered is longer than what's visible (the textbox length), how do you make it so that the beginning chunk of text is visible (instead of the last part of...
11
by: carriolan | last post by:
Hi I have a very simple problem indeed, but I am unable to solve it. I am inputing a short date into an unbound text box with a short date input mask. I am in the UK so my date format is...
1
by: gellert | last post by:
Hello guys, I have a Datagrid and .AllowPaging=true.... it is working well but I'd like to page automatically after some seconds. So the whole solution is a screen in our company showing some...
4
by: DEEAS | last post by:
var DateString=(new Date("")).toString(); 1-How do you get the DateString to give you the Date Time format that you want ? 2- How can you add a few more seconds to that Date value and...
34
by: -Lost | last post by:
I'm REALLY liking this so far. And for those who welcome something a little less cryptic than what the resident date guru offers, here's a chance to try something fairly elegant and definitely...
2
by: ShaggyMoose | last post by:
I want to apply an array of arguments against the Date constructor to set a specific date/time. I can't seem to find the syntax to do this. Using eval to expand the array into seperate arguments...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.