Java question please - whats wrong

Permabanned
Joined
9 Apr 2006
Posts
1,608
Can anyone spot a mistake in this please:

Code:
<script language="JavaScript">
var days = new Array("","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var months = new Array("","January","February","March","April","May","June","July","August","September","October","November","December"); 
var dateObj = new Date()
var wday = days[dateObj.getDay() + 1]
var lmonth = months[dateObj.getMonth() + 1]
var date = dateObj.getDate()
var enddate = ""
if ((date > 3) && (date < 21)) 
	enddate = "th";
if ((date > 23) && (date < 31)) 
	enddate = "th";
if ((date > 0) && (date < 2)) 
	enddate = "st";
if ((date > 20) && (date < 22)) 
	enddate = "st";
if ((date > 30) && (date < 32)) 
	enddate = "st";
if ((date > 1) && (date < 3)) 
	enddate = "nd";
if ((date > 21) && (date < 23)) 
	enddate = "nd";
if ((date > 2) && (date < 4)) 
	enddate = "rd";
if ((date > 22) && (date < 24)) 
	enddate = "rd";
var frontyear = ""
var year = dateObj.getYear()
if ((year > 98) && ( year < 2000))
	frontyear = "2";
else
	frontyear = "";
document.write(wday + ", " + lmonth + " " + date + enddate + ", " + frontyear + year)
</script>

My year is showing 2107 on the home page.

Thanks in advance.

Jon
 
Use getFullYear() instead of getYear() - then you don't have to bother doing any of that frontYear stuff (and avoid y2100 problems ;) )

Some other comments:

- This is javascript, not java. They are completely different things.

- Your if statements to work out enddate is totally confusing and difficult to check the logic. Try to think of a simpler way of doing it.
 
scorza said:
Use getFullYear() instead of getYear() - then you don't have to bother doing any of that frontYear stuff (and avoid y2100 problems ;) )

Some other comments:

- This is javascript, not java. They are completely different things.

- Your if statements to work out enddate is totally confusing and difficult to check the logic. Try to think of a simpler way of doing it.


Many thanks for your time.

Javascript, sorry, I do know the difference, "my bad."

I will try what you said - thanks mate :)

Jon
 
Back
Top Bottom