Get the Current Year in JavaScript

by Dinesh 2014-03-01 17:40:43

<h1>Get the Current Year in JavaScript
</h1>Simple JavaScript code that returns current year value by using of getFullYear() function.

<p id="scarp">Click the button to display current year.</p>
<button onclick="getYear()">Get Current Year</button>
<script>
function getYear()
{
var currentTime = new Date()
var year = currentTime.getFullYear()
document.write(year)
}
</script>
OutPut:
2014

Source code:
function getYear()
{
var currentTime = new Date()
var year = currentTime.getFullYear()
document.write(year)
}

761
like
0
dislike
0
mail
flag

You must LOGIN to add comments