Created
November 22, 2017 08:14
-
-
Save gitname/597cdc5afc81cd568ef27a66ce7be04a to your computer and use it in GitHub Desktop.
Construct copyright date range on client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<!-- ... --> | |
</head> | |
<body> | |
<!-- ... --> | |
<p> | |
© <span id="copyright-year-initial">2017</span><span id="copyright-year-separator"></span><span id="copyright-year-current"></span> | |
</p> | |
<script> | |
(function () { | |
var constructCopyrightMessage = function () { | |
var initialYear = parseInt(document.getElementById("copyright-year-initial").innerHTML); | |
var currentYear = (new Date()).getFullYear(); | |
if (initialYear < currentYear) { | |
document.getElementById("copyright-year-separator").innerHTML = "-"; | |
document.getElementById("copyright-year-current").innerHTML = currentYear.toString(); | |
} | |
}; | |
// Change "(c) 2017" to "(c) 2017-2018" when 2018 arrives. | |
constructCopyrightMessage(); | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment