PDA

View Full Version : having problems with Date() object


dulciew
10-15-2002, 04:49 AM
I have a book which tells me to use the following code to create a date:

var tNow=new Date()

var tlocDate=tNow.toLocaleString()

var tDate=tlocDate.substring(0,10)

document.write("Welcome, today is " +tDate+)


and the date should display in Internet Explorer as follows:

10/15/2002

but it comes out:

Tuesday 1

instead.

I know there are lots of ways to display the date, but my question is why does it appear with the day in full, instead of the short date.

Can anyone help.

Also, I have seen the date something like:

today=new Date(dd/mm/yyyy)

but I can't get this to work either.

Help Please.




:confused:

ahosang
10-15-2002, 05:01 AM
That's a bad way as the toLocaleString() method returns in a variety of formats depending on browser and platform.
Try:
var tNow=new Date();
var m=tNow.getMonth()+1;
var date=tNow.getDate();
var year=tNow.getFullYear();
var tDate=m+"/"+date+"/"+year;
document.write("Welcome, today is " +tDate+);

dulciew
10-15-2002, 05:11 AM
Yes I think its not a good way either, but I'm really moreinterested in why it displays as it does. In IE it is supposed to be: 15/10/2002 and not the long date as shown. Is there some setting I can change. It has worked for me in the past and now all of a sudden it doesn't and I'm using the same browser and I'm wondering if someone may have changed something in IE.

Thanks

ahosang
10-15-2002, 05:37 AM
You might have updated IE's version. Are you on the same computer?

PauletteB
10-15-2002, 07:25 AM
In IE it is supposed to be: 15/10/2002

that is, if your Control Panel / Regional Settings are set to return that format.

If set at d-MMM-yy it would return 15-Oct-02

You most likely changed your Control Panel / Regional Settings / Date format.

Maybe???

dulciew
10-16-2002, 12:50 AM
Thank you PauletteB and ahosang. Both of your replies have answered my question.