Saturday, March 1, 2014

Get Current Date, Month & Year in JavaScript

Get Current Date, Month & Year in JavaScript

Simple JavaScript code to display current date, month and year by getFullYear() method.

<html>
<body>
<p>Click the button to display the date & year.</p>
<button onclick="getYear()">Current Year</button>
<script>
function getYear()
{
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
document.write(month + "/" + day + "/" + year)
}
</script>
</body>
</html>

Example:




Copy Code:

No comments:

Post a Comment