JRS: In article <
[email protected]>,
dated Wed, 5 Jul 2006 02:15:12 remote, seen in
news:comp.lang.javascript said:
I am going to define a date variable by specify a Date.
How can I do so?
I have tried below:
var d = new Date(2006, 11, 30); //I expect this return 30 Dec 2006
It will certainly not do that. It will generate a Date Object whose
..valueOf() (which tends to show the true internal form of things) is the
number of milliseconds from 1970-01-01 00:00:00 GMT to the beginning of
2006-12-30 in your computer's local time; your computer should be
correctly set for locality (including Summer time, for those in the
Southern Hemisphere).
but it shows "undefined-11-2006"
That's an unspecified "it"; the routine you use to provide the date part
is evidently grossly defective, and that for the month part may be OK if
you add 1. Unseen code is generally wrong and cannot be corrected here.
and I found IE6 cannot using:
var d=new Date;
That should be new Date(), but new Date may do as well.
BUT it sets the current local date/time ...
If that date/time does not exist in 2006, an unexpected change will
occur. Some code using new Date() can perhaps only be fully verified on
February 29th.
d=setMonth(11,30) // or d=setMonth(11), both of these statements fail,
You've omitted for each the d. which you have with setFullYear().
error on without this method.
Read the newsgroup FAQ; see sig below; never attempt to set a date
piecemeal; never call new Date() unless you want the *current*
value, since new Date(0) gives a consistent result several times
faster. And check what you write, both in coding and here in News.
Post complete "working" examples, saying what you think it should do,
stating the result that is hoped for, and what the result is.