Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date problem

Status
Not open for further replies.

tboerner

Programmer
Oct 19, 2001
23
US
The following code gives me what I want for the PC, which is: "11/01/2001"

But on the MAC it returns: "Thursday,"

currentDate = new Date()
document.write(currentDate.toLocaleString().substring(0,10));

Anybody know how to make it return "11/01/2001" for both operating systems.

IE is the browser in both scenarios.
 
Well, you have many choices. You can try these different methods to see if you can find common ground.
Code:
document.write(currentDate.toString());
document.write(currentDate.toGMTString());

The other option would be to build the string using..
Code:
currentDate.getMonth()
currentDate.getDate()
currentDate.getYear()

However, be prepared for some tricky things with getMonth() and getYear(). getMonth() is zero based so it returns 0 for January. And while IE will return 2001 for getYear(), Netscape will return 101 (Current year minus 1900). But with some browser detection and a little math, you can get these methods to work just fine.

ToddWW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top