Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Community Discussions (All other subjects)
 Javascript date error using Firefox?
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

MarkJH
Senior Member

United Kingdom
1722 Posts

Posted - 04 March 2006 :  13:43:27  Show Profile  Visit MarkJH's Homepage
Can anyone tell me why this simple JavaScript code which displays a date:

<script type="text/javascript">
today=new Date(); // Initialize Date in raw form
date=today.getDate(); // Get the numerical date
year=today.getYear(); // Get the year
day = today.getDay(); // Get the day in number form (0,1,2,3,etc.)
month=today.getMonth()+1; // Get the month

// Make day number value correspond to actual day name
var dayName=new Array(7)
dayName[0]="Sunday";
dayName[1]="Monday";
dayName[2]="Tuesday";
dayName[3]="Wednesday";
dayName[4]="Thursday";
dayName[5]="Friday";
dayName[6]="Saturday";

// Add suffix to date (1st, 2nd, 4th, etc.)
if (date==1) suffix=("st");
else if (date==2) suffix=("nd");
else if (date==3) suffix=("rd");
else if (date==21) suffix=("st");
else if (date==22) suffix=("nd");
else if (date==23) suffix=("rd");
else if (date==31) suffix=("st");
else suffix=("th");

// Make month number correspond to month name
if (month==1) monthName=("January");
else if (month==2) monthName=("February");
else if (month==3) monthName=("March");
else if (month==4) monthName=("April");
else if (month==5) monthName=("May");
else if (month==6) monthName=("June");
else if (month==7) monthName=("July");
else if (month==8) monthName=("August");
else if (month==9) monthName=("September");
else if (month==10) monthName=("October");
else if (month==11) monthName=("November");
else monthName=("December");

// Write date
document.write(dayName[day] + " "  + date + suffix + " " + monthName + " " + year + " ");
                        </script>


Works fine in IE6/7 displaying

Saturday 4th March 2006

but in Firefox displays

Saturday 4th March 106


Bandlink.net - http://www.bandlink.net/
Bandlink Music Forums - http://www.bandlink.net/forum/

dayve
Forum Moderator

USA
5820 Posts

Posted - 04 March 2006 :  14:17:46  Show Profile  Visit dayve's Homepage
use getFullYear

http://www.quirksmode.org/js/datecompat.html


Edited by - dayve on 04 March 2006 14:25:20
Go to Top of Page

Davio
Development Team Member

Jamaica
12217 Posts

Posted - 04 March 2006 :  14:31:04  Show Profile
As dayve said.
Some more info on it from the Mozilla Development Center:
GetYear(), GetFullYear()

Support Snitz Forums
Go to Top of Page

MarkJH
Senior Member

United Kingdom
1722 Posts

Posted - 04 March 2006 :  14:33:04  Show Profile  Visit MarkJH's Homepage
Thanks for that, Dayve. Worked a treat.

Bandlink.net - http://www.bandlink.net/
Bandlink Music Forums - http://www.bandlink.net/forum/
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.29 seconds. Powered By: Snitz Forums 2000 Version 3.4.07