Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (7k points)
How to get the current year in JavaScript?

1 Answer

0 votes
by (13.1k points)

You can get the current year by using getFullYear() with the following syntax:

new Date().getFullYear();

An example for this is:

<!Doctype HTML>

<html>

<title></title>

<body>

<span id=”year”>y</span>

<script>

document.getElementById(“year”).innerHTML=new Date().getFullYear();

</script>

</body>

</html>

Want to be a web developer? Check out the full stack developer course from Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jan 28, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
asked Apr 9, 2021 in Java by sheela_singh (9.5k points)

Browse Categories

...