It's not a good practice to use document.write
. You can learn more about document.write by pressing here. Don't use document.write unless if you have to. Here's a somewhat friendly javascript/html solution. And yes, there is studies on how InnerHTML is bad, working on a more friendly soultion.
document.getElementById("year").innerHTML=(new Date).getFullYear();
? javascript
? html
<span id="year"></span>
You can place the javascript code in your html, but it would look best in a javascript file. Very clean answer. Personally, I recommend writing the current year with PHP. Probably the safest answer.
If you want to write the current year with PHP, you can do so with this small code.
<?php echo date("Y"); ?>
Remember in order to apply this PHP code, your webpage file has to be PHP.