Date Object - Adding

D

dan

I could find no documentation that the Date object has useful wrapping
properties. For example, write(new Date(2007, 11 + 1, 1)) results in
January 1st 2008. And write(new Date(2007, 0, 31 + 1)) results in
February 1st 2007. I have 'JavaScript The Definitive Guide 5th Edition'
and it does not mention this. All the examples I see on the WEB are
laborious functions!

Dan
 
L

-Lost

I could find no documentation that the Date object has useful wrapping
properties. For example, write(new Date(2007, 11 + 1, 1)) results in
January 1st 2008. And write(new Date(2007, 0, 31 + 1)) results in
February 1st 2007. I have 'JavaScript The Definitive Guide 5th Edition'
and it does not mention this. All the examples I see on the WEB are
laborious functions!

The Date object can be a beast to tame.

http://www.hunlock.com/blogs/Javascript_Dates-The_Complete_Reference

Is a great writeup. Also, here:

http://www.devguru.com/technologies/javascript/10585.asp

Shows an example of creating a date in the future, then using
subtraction to minus the current date from the date in the future.

http://www.brainjar.com/js/calendar/

Date's flexibility is key to a JavaScript calendar application.

Specifically, in the book you are reading on page 38:

3.9 The Date Object
xmas = new Date(97, 11, 25);
xmas.setYear(xmas.getYear() + 1); // change the date to next Christmas

That is the code from the 3rd edition, but the exact page (if I remember
correctly) for the 5th. I am too lazy to hunt for my 5th edition right
this moment.

Also, in the 5th edition see page 617 for examples of "subtracting the
milliseconds from another date" or something along those lines.

Any of this help?
 
D

dan

-Lost said:
The Date object can be a beast to tame.

http://www.hunlock.com/blogs/Javascript_Dates-The_Complete_Reference

Is a great writeup. Also, here:

http://www.devguru.com/technologies/javascript/10585.asp

Shows an example of creating a date in the future, then using
subtraction to minus the current date from the date in the future.

http://www.brainjar.com/js/calendar/

Date's flexibility is key to a JavaScript calendar application.

Specifically, in the book you are reading on page 38:

3.9 The Date Object
xmas = new Date(97, 11, 25);
xmas.setYear(xmas.getYear() + 1); // change the date to next Christmas

That is the code from the 3rd edition, but the exact page (if I remember
correctly) for the 5th. I am too lazy to hunt for my 5th edition right
this moment.

Also, in the 5th edition see page 617 for examples of "subtracting the
milliseconds from another date" or something along those lines.

Any of this help?


Yeah, but say I just want to add 1 month every time a it executes say
once per month. All I have to is

today = new Date();
currentYear = today.getFullYear();
currentMonth = today.getMonth();

testDate = new Date (currentYear, currentMonth + 1, 1)

and I don't have to worry "oh is it month 11, wrap to 0".
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
t>, Fri, 4 May 2007 09:53:56, (e-mail address removed) posted:
I could find no documentation that the Date object has useful wrapping
properties. For example, write(new Date(2007, 11 + 1, 1)) results in
January 1st 2008. And write(new Date(2007, 0, 31 + 1)) results in
February 1st 2007. I have 'JavaScript The Definitive Guide 5th
Edition' and it does not mention this. All the examples I see on the
WEB are laborious functions!


You should have read the newsgroup FAQ, which links to the ECMA-262
spec. It should also cite ISO 16262, which is a more recent version
with at least one error corrected. Careful study should show the
property to be required.

And you should have seen what the FAQ says about dates and times.

If you had read the Web more thoroughly, you would have found at least
one site which uses the feature that you describe.

Note : In Firefox 2.0.0.3, Date.UTC(Y, M, D) treats D<1 as D=1.


It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 
D

Dr J R Stockton

In comp.lang.javascript message <CNudnU0XG8BwyabbnZ2dnUVZ_h-
(e-mail address removed)>, Fri, 4 May 2007 11:45:35, -Lost <maventheextrawords@
techie.com> posted:
Specifically, in the book you are reading on page 38:

3.9 The Date Object
xmas = new Date(97, 11, 25);
xmas.setYear(xmas.getYear() + 1); // change the date to next Christmas

That dies not illustrate the OP's point ; new Date(97, 11+12, 25)
and new Date(97, 11, 25+365) would do so.
 
L

-Lost

Dr said:
In comp.lang.javascript message <CNudnU0XG8BwyabbnZ2dnUVZ_h-
(e-mail address removed)>, Fri, 4 May 2007 11:45:35, -Lost <maventheextrawords@
techie.com> posted:

That dies not illustrate the OP's point ; new Date(97, 11+12, 25)
and new Date(97, 11, 25+365) would do so.

And? I responded specifically to the original poster saying that the
JavaScript book (that is cited as a resource in the FAQ) did not contain
examples of "date arithmetic."

I showed that there were examples.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,270
Latest member
TopCryptoTwitterChannels_

Latest Threads

Top