Kinda Code
Home/React/Displaying the Current Year in React

Displaying the Current Year in React

Last updated: March 03, 2023

In React, you can render the current year like this:

<div>{new Date().getFullYear()}</div>

The complete example below presents a copyright symbol along with the current year (you can see this everywhere on the internet).

Screenshot:

The code:

// KindaCode.com
// src/App.js
function App() {
  return <div style={styles.container}>
    <h1 style={styles.copyright}>&copy;{new Date().getFullYear()} KindaCode.com</h1>
  </div>;
}

const styles = {
  container: {
    width: '100vw',
    height: '100vh',
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
  },
  copyright: {
    color: 'blue'
  }
};

export default App;

Further reading:

You can also check our React category page and React Native category page for the latest tutorials and examples.

Related Articles