How to Make a Web Page Always Display the Current Year

How to Insert the Current Year into a Web Page Using JavaScript

How to Make a Web Page Always Display the Current Year

by Christopher Heng,

I was asked by a visitor how he could insert the current year into his web page and have it automatically update every year without manual intervention on his part. This can be easily done by inserting a bit of JavaScript into the portion where you normally place the year.


How to Display the Current Year in JavaScript

If you wish to display the current year in your visitor's local time zone, insert one of the following blocks of code at the location you will normally type the year.

If you are not sure which whether your page uses HTML 4.01 or HTML5, just use the HTML 4.01 code (which is valid in both HTML 4.01 and HTML5). Although I put the ideal code for each version in accordance with the recommendations of the web standards of that version, in practice, all modern web browsers treat both snippets identically.

Demo: the current year (in your local time) is .

The HTML code for the above paragraph, to serve as an example for those who are still unsure where to embed the code on your page, is:

<strong>Demo</strong>: the current year (in your local time) is
<script type="text/javascript">document.write( new Date().getFullYear() );</script>.

Using UTC or GMT Time

Those who want to print the year in Coordinated Universal Time (that is, UTC or GMT) should use one of the following instead.

Demo: the current year in UTC is .

For most of the year, the numbers displayed by both the local time and UTC snippets will be identical. Depending on your location, it may be different during certain hours on the 31st of December and the 1st of January, when the year changes in one part of the world, but not yet in another.

Copyright © 2018-2019 Christopher Heng. All rights reserved.
Get more free tips and articles like this, on web design, promotion, revenue and scripting, from

thesitewizard™ News Feed (RSS Site Feed)  Subscribe to newsfeed

Do you find this article useful? You can learn of new articles and scripts that are published on by subscribing to the RSS feed. Simply point your RSS feed reader or a browser that supports RSS feeds at You can read more about how to subscribe to RSS site feeds from my RSS FAQ.

Please Do Not Reprint This Article

This article is copyrighted. Please do not reproduce or distribute this article in whole or part, in any form.

Related Articles

New Articles

Popular Articles

How to Link to This Page

It will appear on your page as:

How to Make a Web Page Always Display the Current Year

Link to Us
No Spam Policy
Privacy Policy
Site Map

Getting Started
Web Design
Search Engines
Revenue Making
Web Hosting
Perl / CGI
.htaccess / Apache


Free webmasters and programmers resources, scripts and tutorials Free How-To Guides
Site Design Tips at
Find this site useful?
Please link to us.