Date() - year missing since clocks changed

O

Orson

I have a page that uses the javascript Date() function to retrieve a date
from the client computer.
The date is then inserted into a note that is saved on a database. The date
is in the format
Thursay Oct 30 2003 10.47am

When I access the page using my computer everything works fine.
A colleague in the UK also uses the page and it was fine up until the clocks
changed last weekend. Now notes that he saves have the date in the format
Thursday Oct 30 10.47am i.e. the year is missing.

Presumably something has happened to the date information on his computer so
that Date() is not getting the year any longer. Can anyone suggest how I
might sort this out?

Thanks
Orson
 
L

Lasse Reichstein Nielsen

Orson said:
Presumably something has happened to the date information on his computer so
that Date() is not getting the year any longer.

Highly unlikely. The Date object is ususally highly resilient about changes.
User code is not.
Can anyone suggest how I might sort this out?

Not without showing us the code that fails.

/L
 
O

Orson

Lasse Reichstein Nielsen said:
Highly unlikely. The Date object is ususally highly resilient about changes.
User code is not.

You are correct. Thanks for getting me to think straight. Next week when I
can check it, I am sure I will find the answer lies in the manner I am
chopping up the Date string which will have changed with the switch from
Summer Time.
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
news:comp.lang.javascript said:
Presumably something has happened to the date information on his computer so
that Date() is not getting the year any longer. Can anyone suggest how I
might sort this out?

Probably you mean new Date() above. The value is a date variable
is stored as milliseconds from 1970-01-01 00:00:00 GMT, and there is no
prospect of the year going absent.

It is conceivable that the year corresponding to the date currently
stored is cached within the object, for efficiency; but even in that
case I would not expect blank or spaces to be returned.

Where the browser is suspected, a questioner should report details of
the system. But it is probable that the code is wrong; it cannot be
diagnosed in more detail without seeing it. Or the database is in
error; arrange to display exactly what is being sent to it.


As you are in NZ, could you check Web <URL:http://www.merlyn.demon.co.uk
/js-date5.htm#Demo>, yellow form, for correctness with NZ selected where
UK initially appears? Select NZ, then Run.
 
L

Lee

Orson said:
You are correct. Thanks for getting me to think straight. Next week when I
can check it, I am sure I will find the answer lies in the manner I am
chopping up the Date string which will have changed with the switch from
Summer Time.

That's a good reason not to get information by chopping up
the Date string. The Date object has methods that return
the month, date, year, day of week, etc.
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
news:comp.lang.javascript said:
You are correct. Thanks for getting me to think straight. Next week when I
can check it, I am sure I will find the answer lies in the manner I am
chopping up the Date string which will have changed with the switch from
Summer Time.

For me,
new Date(2003, 05) Sun Jun 1 00:00:00 UTC+0100 2003
new Date(2003, 11) Mon Dec 1 00:00:00 UTC 2003


**NEVER** lightly disassemble a string whose format is not rigorously
defined either by yourself or in a document which you have reason to
believe is heeded. Consider whether your browser supplier is likely to
heed documents.

Not only may there be an overlooked variation such as above, but there
may be a variation with browser (etc.) version, or with localisation.

Use the string output functions at most for showing to a human who can
be expected to recognise what it means.

Avoid the string input functions, except that D = new Date("2003/11/01")
seems safe, with 4-digit year, YMD order, and / separator (anyone find
otherwise?), and strings with 4-digit years and month names seem safe if
the spelling can be trusted worldwide.




I've noticed that (in my MSIE4) J = Date.UTC(Year) accepts years
outside the Date Object range - it gives a big number for year 1E297,
and Infinity for 1E298. For large N, Date.UTC(N)/N is, as expected,
close to 31556952000.
 
O

Orson

Dr John Stockton said:
JRS: In article <[email protected]>, seen in


Probably you mean new Date() above. The value is a date variable
is stored as milliseconds from 1970-01-01 00:00:00 GMT, and there is no
prospect of the year going absent.

It is conceivable that the year corresponding to the date currently
stored is cached within the object, for efficiency; but even in that
case I would not expect blank or spaces to be returned.

Where the browser is suspected, a questioner should report details of
the system. But it is probable that the code is wrong; it cannot bet
diagnosed in more detail without seeing it. Or the database is in
error; arrange to display exactly what is being sent to it.


As you are in NZ, could you check Web <URL:http://www.merlyn.demon.co.uk
/js-date5.htm#Demo>, yellow form, for correctness with NZ selected where
UK initially appears? Select NZ, then Run.

It was in the code.
I am embarrassed to say that I had chopped up the string without regard for
the consequences. I am now using the proper date object methods and the
problem is resolved.

With regard to your demo page, everything appears in order when I set the
form to NZ and click run.

Thank you all for your help.

Orson
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top