Dr said:
It is not an arbitrary date; it is 1970-01-01 00:00:00 GMT.
This is an arbitrary date. It is constant but the date itself is
arbitrary. There was no reason to pick that particular date other than
for the fact that at one point in time someone did and it's been a part
of various computer languages that resolve julian dates ever since.
The first figure corresponds to Wed Nov 22 03:00:00 UTC 2006. Evidently
you do not recall that dates are generally assumed by Javascript to be
in the user's time zone using the Summer Time rules currently
appropriate (according to the browser/OS).
Evidently for the problem described it does not matter. Since we're
doing a relative check between two dates it doesn't matter if the user
is in china and the parser is resolving everything to GMT as long as
both dates resolve to the same timezone which they will unless a
time-zone deliberately gets into the mix, which the quaint b/c format
seems not to allow.
Not to an int, but to a Number. Not a cast, which is a
re-interpretation, rather than a transformation, of a bit pattern. For
the purpose, we deprecate multiplication; use unary +, as per the FAQ.
document.write(date1); ----> [object]
document.write(date1*1); --> very long integer.
+ is a concatenation element in javascript and may yield unpredictable
results. * guaranteed the conversion without risking concatenation or
requiring additional elements to contain concatenation which would
increase the complexity.
I will, however, concede that in a formal setting date1.getTime() would
be the best practice.
You forgot months! One can get the exact time in milliseconds (ignoring
Leap Seconds); but "exact" conversion to days weeks months years, all of
which are of variable length, is unrealistic.
I'm sorry but this is wrong. If you have the exact number of
miliseconds between two dates as well as the two original starting and
ending dates you can indeed find the exact number of days, weeks,
months, years and any other element you wish to find. You can test this
for yourself by creating a date object for today, and a date object for
some point in the future (even a future which includes a leap year)
convert both to julian numbers, obtain the difference, add the
difference to the original julian number (today), and you'll find on
inspecting the new date that the date, year, month, etc all match up to
your original future date despite the "inexactness" of dealing with leap
years and all that other stuff.
If the date object is able to find this, it does indeed mean that exact
conversions are exactly what is happening which means if you want the
information badly enough, you will be able to get it from elegant
time/date algorithms right on down to setting up a stash of counters and
marking any changes as you brute force a date object second by second
between the two values.
It's a good idea to read the newsgroup and its old FAQ. See below.
And it's a good idea to not be so concerned with the leaves on the trees
that you get lost in the forest. Just because the answer is not the way
YOU would have done it doesn't mean that it's not a correct or valid
answer, this is especially true when the appeal to authority gets kicked
up to textbooks or, in this case, FAQs.