Create a new Date()
object and call getFullYear()
:
new Date().getFullYear() // returns the current year
Example usage: a page footer that always shows the current year:
document.getElementById("year").innerHTML = new Date().getFullYear();
footer { text-align: center; font-family: sans-serif; }
<footer> ©<span id="year"></span> by Donald Duck </footer>
Run code snippetExpand snippet
See also, the Date()
constructor’s full list of methods.
Related Posts:
- Current time formatting with Javascript
- How to format a JavaScript date
- How to format a JavaScript date
- How to format a JavaScript date
- How do I get the current date in JavaScript?
- Get String in YYYYMMDD format from JS date object?
- Compare two dates with JavaScript
- Compare dates with javascript
- Add days to JavaScript Date
- Parsing a string to a date in JavaScript
- Format JavaScript date as yyyy-mm-dd
- Add days to JavaScript Date
- How to validate date with format “mm/dd/yyyy” in JavaScript?
- How to subtract date/time in JavaScript?
- Getting current date and time in JavaScript
- Shortest way to print current year in a website
- Validate date in dd/mm/yyyy format using JQuery Validate
- Convert a Unix timestamp to time in JavaScript
- How to subtract days from a plain Date?
- How to add 30 minutes to a JavaScript Date object?
- How do you convert a JavaScript date to UTC?
- Convert UTC Epoch to local date
- Convert normal date to unix timestamp
- Check time difference in Javascript
- How to convert date to timestamp?
- How to format a UTC date as a `YYYY-MM-DD hh:mm:ss` string using NodeJS?
- Moment Js UTC to Local Time
- Get hours difference between two dates in Moment Js
- Javascript: getFullyear() is not a function
- Check if a string has a certain piece of text [duplicate]
- JavaScript Array splice vs slice
- How does Access-Control-Allow-Origin header work?
- What’s the best way to convert a number to a string in JavaScript?
- React Native: this.setState is not a function
- How to perform string interpolation in TypeScript?
- forEach is not a function error with JavaScript array
- Short circuit Array.forEach like calling break
- How to create an accurate timer in javascript?
- How to check if two arrays are equal with JavaScript?
- What is causing the error `string.split is not a function`?
- Does JavaScript have a built in stringbuilder class?
- Javascript TypeError: Cannot read property ‘indexOf’ of undefined
- Pass react component as props
- Get a random item from a JavaScript array
- How to fix Cannot find module ‘typescript’ in Angular 4?
- Origin null is not allowed by Access-Control-Allow-Origin
- jQuery: Uncaught Error: Syntax error, unrecognized expression
- What is the difference between String.slice and String.substring?
- Only on Firefox “Loading failed for the script with source”
- How do you use a variable in a regular expression?
- How to embed a youtube playlist with a sidebar
- How can I remove all CSS classes using jQuery/JavaScript?
- How to add a button dynamically using jquery
- External JavaScript Not Running, does not write to document
- What does `node –harmony` do?
- Get integer value of the current year in Java
- Custom Post Type Archives by Year & Month?
- How to load wp_editor via AJAX
- Preventing YouTube embeds loading multiple instances of player JS?
- How to display date such “x ago”
- What happened to convertEntities?
- Modify Date Format to German
- Ordering posts by anniversary using only day and month
- How to handle malformed response from WP REST API?
- Can I share predefined fonts from theme_support with a gutenberg component?
- Trouble adding JavaScript in visual editor (Sharpspring embed code)
- WP Admin missing icons, numerous JavaScript errors, but only when SCRIPT_DEBUG is false
- How to make wordpress URLS google friendly for ajax driven sites?
- Events are all showing the current date
- Get a default value of the Customizer setting using wp.customize API (JS)
- Google PageSpeed Enable Compression isn’t working?
- How can I add Javascript in the header of all post pages and only post pages
- Format Date for Manual Insertion into post
- Run a jquery script on on a certain template page
- I am trying to get cutom post cout by month of current taxonmy term
- Post repeated when opening in overlay, how do I solve this? [closed]
- Making POST request with AJAX returns a 400 error (without jQuery)
- How to load jQuery in TOP of wp_footer?
- Include Jquery libraries in wordpress theme?
- Add captcha validation to my custom form for Frontend posting
- AddThis Sharing Bar Not Displaying on Custom Page Template – JS conflict?
- Bootstrap bundle present in page source but not working
- uncaught TypeError: Cannot read properties of null (reading ‘classList’) custom plugin
- How do I minify a plugins CSS/JS code?
- How can I put content before my custom post type default pages?
- Access checks with custom REST endpoints and backbone
- How to pass data to javascript in custom widget class
- Replacing entire tag with shortcode – JavaScript [duplicate]
- Inserting javascript file into theme template?
- Notify user we would like them to clear their cookie. Provide a working button to clear cookies for user
- WordPress Admin Thickbox: Remove Margins/Padding
- Call full image url instead of stylsheet directory url in JS for Infinite Scroll Function
- Custom Javascript not working? [closed]
- How would I get this to work – send to post from thick box
- Why are some custom javascript files working but some are not
- Add title and caption to thumbnail image on mouseover
- How to add additional JavaScript code [duplicate]
- Cannot get custom javascript to execute on page
- How to make a rest style plugin?
- Use WordPress Built In Jquery