...

View Full Version : Why is Date functionality done this way?



RadarBob
08-27-2002, 12:50 AM
OK, I've been reading the threads on Date stuff with great interest and I've begun to wonder...

Why do most of y'all code date arithmetic using milliseconds? I'm no expert (yet) but it's clear that using milliseconds is not the only way. Compared to the alternative technique, it's definitely more convoluted looking. So why do it the hard way?

For example why multiply by 86,400,000 (or whatever it is) when adding a simple integer will increment by any number of days?

I've seen a very comprehensive javascript date web site and the author says it's "folly" to do date arithmetic using milliseconds.
http://www.merlyn.demon.co.uk/js-dates.htm

So how about it? What valid reasons are there one way or the other?

joh6nn
08-27-2002, 01:46 AM
because there are built in Date methods that convert Dates to milliseconds. also, a millisecond representation of a date, is exact; you don't have to worry about the format of the date, like MMDDYY or DDMMYY.

PauletteB
08-27-2002, 08:55 AM
Radar

For example why multiply by 86,400,000 (or whatever it is) when adding a simple integer will increment by any number of days?

actually it's 86,400

60 seconds per minute
60 minutes per hour
24 hours per day is

86,400 seconds per day.

Another note...
Atomic time is based on elapsed time in seconds since January 1, 1900

WebTime - 27-Aug-2002
======================
Started up Microsoft wsock32.dll, ver2.2, 32bit of Jun 7 2000, at 21:34:15.
Socket 52 created
Connecting to Boulder, Colorado - A
URL is time-a.timefreq.bldrdoc.gov
At IP Address 132.163.4.101
Connected to Boulder, Colorado - A
URL is time-a.timefreq.bldrdoc.gov
At IP Address 132.163.4.101
Waiting to receive ...
Received elapsed time of 3239420060 seconds since January 1, 1900
System date and time successfully changed
From: 27-Aug-2002 - 01:54:19.690
To: 27-Aug-2002 - 01:54:19.970
Socket closed.

mordred
08-27-2002, 10:12 AM
That's a good question actually. I can only speak for myself and for me, it's definitely a matter of too long exposure to PHP scripting... PHP doesn't have Date objects comparable to JavaScript. Also, when transforming a date into it's milisecond value, I have the feeling that I'm very exact now cause I'm sort-of dealing with the "lowest common denominator". Which is just plain wrong, but I tend to forget that most of the time ;)

But there are really uses of comparing dates in miliseconds - even the page you posted contains examples of these (for instance, trying to find out how many days elapsed between two Date objects). The author only said that it's a folly to



Using millisecond arithmetic where daycount arithmetic is appropriate


So there may be occasions where daycount arithmetic is not appropriate. And vice versa of course.

Will be using more daycount arithmetic in the future I think. Well, only if I think it's appropriate.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum