Helpful Information
 
 
Category: JavaScript Development
Javascript clock

Hi,

I apologise if this is problem has been posted previously ( I am quite sure somewhere it has). I have searched, but it is impossible to comb through all the entries.

I am trying to display the current date on a web page using javascript.

The script I am using is as follows

//array with names of days of the week
var days = new Array( "Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday" );

//array with names of months
var months = new Array( "January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December" );
var today = new Date();

var sDay = days[today.getDay()];
var sMonth = months[today.getMonth()];

var date = sMonth + " " + today.getDate() + ", " + today.getYear();
document.write(sDay + ", " + date);

Unfortunately, this returns the year as 101 in Netscape. I have looked around and can see that the today.getyear is the problem, and needs to be substituted with something along the lines of getFullYear.

Any help would be appreciated.

Thanks in advance
Null

I don't understand what the problem is.

Just use the date.getFullYear() function. If you're using date.getYear() you need to add 1900 to it, so it is correctly returning 101. Note that getFullYear() only works with browsers that support JavaScript 1.3 or greater.










privacy (GDPR)