How to add a Digital Clock in Next.js ?
Last Updated :
24 Jul, 2024
Adding a digital clock to your Next.js application can enhance the user experience by providing real-time updates in an aesthetically pleasing manner. We can simply add it with packages available on NPM. In this article, we are going to learn how we can add Clock in Next.js
Approach
To add our Clock we are going to use the react-live-clock package. The react-live-clock package helps us to add a clock anywhere in our app. So first, we will install the react-live-clock package and then we will add a clock on our homepage.
Steps to Create Next.js App
Step 1: Initialize a new next.js project using the below command
npx create-next-app gfg
Step 2: Move to the Project directory
cd gfg
Step 3: Install the required package react-live-clock using the below command:
npm i react-live-clock
Project Structure:

The updated dependencies in the package.json file:
"dependencies": {
"next": "14.2.4",
"react": "^18",
"react-dom": "^18",
"react-live-clock": "^6.1.23-beta"
}
Example: This example demonstrate adding a digital clock in next.js application using react-live-clock npm package.
JavaScript
// pages/index.js
import React from "react";
import Clock from 'react-live-clock';
export default function MyQuotesSlider() {
return (
<div>
<h3>GeeksforGeeks Digital Clock</h3>
<Clock
format={'h:mm:ssa'}
style={{fontSize: '1.5em'}}
ticking={true} />
</div>
);
}
Explanation: In the above example first, we are importing the Clock component from the installed package. After that, we are adding the format, style, and other parameters in our clock component.
Steps to run the application: Run the below command in the terminal to run the app.
npm run dev
Output:

Conclusion
Integrating a digital clock into your Next.js app is straightforward. By installing a suitable package, creating a clock component, and adding it to your pages, you enhance your app's functionality and user experience with real-time updates.
Similar Reads
How to add Calendar in Next.js ? Adding a calendar to a Next.js application enhances scheduling and event management. We can just install and use the available npm package. In this article, we are going to learn how we can add a calendar loader in NextJS.ApproachTo add our calendar we are going to use the react-calendar package. Th
2 min read
How to add Timer in Next.js ? In this article, we are going to learn how we can add Timer in NextJS. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components conditionally.
2 min read
How to Add ChartJS in NextJS 13? Chart.js in Next.js is the package used to create interactive and visually appealing charts, such as line charts, bar charts, and more, seamlessly integrated into Next.js applications. In this article, we will explore the demonstration of various charts in the NextJS application. Table of Content Im
3 min read
How to Add Tweets in Next.js ? Adding tweets in Next.js involves using Twitter's embed feature or API to display tweets. You can embed tweets directly in components or fetch and display them using server-side rendering or client-side data fetching. In this article, we are going to learn how we can add Tweets in NextJs.ApproachTo
2 min read
How to Add Simple DatePicker in Next.js ? In this article, we are going to learn how we can add a Simple Datepicker in NextJs. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components
2 min read