
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to display only the current year in JavaScript?
To display only the current year, use getFullYear(). Following is the code −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initialscale=1.0"> <title>Document</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> </head> <body> <h1> The Current Year=<span id="theCurrentYear"></span> </h1> <script> document.getElementById("theCurrentYear").innerHTML = new Date().getFullYear(); </script> </body> </html>
To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.
Output
This will produce the following output −
- Related Articles
- How to get the only current year in JavaScript?
- How to get the current year in JavaScript?
- How to print current year in JavaScript?
- How to display current connection info in MySQL?
- How to display the name of the Current Thread in C#?
- How to display the current working directory in the Linux system?
- How to get current day, month and year in Java 8?
- How to get the current date to display in a Tkinter window?
- Get the days remaining in current year in Java
- How to display only hour and minutes in MySQL?
- Display four-digit year in Java
- Display two-digit year in Java
- How can we insert current year automatically in a YEAR type column of MySQL table?
- Display the current mask in Numpy
- Tkinter-How to get the current date to display in a tkinter window?

Advertisements