Forum Moderators: open
There are a few date functions that would be good to know:
getDate() = Date of the month (1-31)
getMonth() = Month (0-11)
getYear() = Years since 1900 (which means that you should add 1900 to the value)
getFullYear() = The actual year (may not work in really old browsers)
getDay() = Day of the week (0-6)
There are lots more... for hours, minutes, seconds, time zones, etc.
<script type="text/javascript">
months = new Array("January", "February", "March", "April" ,"May", "June", "July" ,"August", "September", "October", "November", "December");
now = new Date();
date = now.getDate();
month = months[now.getMonth()];
year = now.getFullYear();
document.write(month + " " + date + ", " + year);
</script>
This would output "December 11, 2003"
Can you tell me how I could modify it to show as: Saturday, December 13 2004
First, I'll assume "2004" was a typo. Then:
1) add the following variable declarations:
days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); day =days[now.getDay()]; 2) then add "day" to the document.write command:
document.write(day + " " + month + " " + date + ", " + year); (Not sure if you want the comma where you displayed it above, but if so just exchange the first " " and the ",")
Incidentally, if you prefer (to shorten your code just a bit), you may omit the set of variable declarations for "day" "date" "month" and "year" and instead expand the document.write command as follows:
document.write(days[now.getDay()] + " " + months[now.getMonth()] + " " + now.getDate() + ", " + now.getFullYear());