Forum Moderators: open
<script type="text/javascript" language="JavaScript">
var dateMod = "" ;
dateMod = new Date();
document.write((1 + dateMod.getMonth()) + "/" + (dateMod.getDate()) + "/" + dateMod.getYear());
</script>
This dispays the year correctly in IE, but not in Mozilla, not in Opera, not in NS. They all show the year as 103 instead of 2003.
Todays Date: 10/12/103
I'm not sure, but it seems like a format string is in order here.
<script language="JavaScript">function dodate() {
var dateis = new Date;
var dayofweek = dateis.getDay();
var dayofmonth = dateis.getDate();
var x = new Array("Sunday,", "Monday,", "Tuesday,", "Wednesday,","Thursday,", "Friday,", "Saturday,");
var interrim;
if (dayofmonth == 1 ¦¦ dayofmonth == 21 ¦¦ dayofmonth == 31) {
interrim = "st";
}
else {
if (dayofmonth == 2 ¦¦ dayofmonth == 22) {
interrim = "nd";
}
else {
if (dayofmonth == 3 ¦¦ dayofmonth == 23) {
interrim = "rd";
}
else {
interrim = "th";
}
}
}
interrim = x[dayofweek] + " " + dayofmonth + interrim;
x = new Array("of January", "of February", "of March", "of April", "of May", "of June", "of July", "of August", "of September", "of October", "of November", "of December");
interrim = interrim + " " + x[dateis.getMonth()] +", ";
x = dateis.getYear();
if (x < 1999) { x += 1900; } return interrim + x;
}
window.document.write(dodate());
</script>
What I don't like about JS dates is that they are only right if the system clock is right.
Consider, too, that a date like 01/12/2003 is interpreted as January 12th in the US and as 1st December in Europe.
Investigate the date formats suggested by ISO 8601 and ANSI X3.30 and especially RFC 3339 for globally unambiguous ways to present the date.