How to Display Time in NuxtJS ?
Last Updated :
10 Dec, 2021
In this article, we are going to learn how we can show time in NuxtJs. Nuxt.js is a free and open-source web application framework based on Vue.js, Node.js, Webpack, and Babel.js. Nuxt is inspired by Next.js, which is a framework of similar purpose, based on React.js.
Approach: To show time in nuxtjs we are going to use the vue-time package. The vue-time package helps us to add a time anywhere in our app. So first, we will install the vue-time package and then we will create a vue-time.js file in our plugins folder then we will add the time in our app.
Create NuxtJS Application:
Step 1: You can create a new NuxtJs project using the below command:
npx create-nuxt-app gfg
Step 2: Now navigate to your app using the following command:
cd gfg
Step 3: Install the required package. Now we will install the vue-time package using the below command:
npm i vue-time
Project Structure: It will look like this.
Step 4: Create a new file with the name 'vue-time.js' inside the plugins folder. After creating the file add the below content in the file.
vue-time.js
import Vue from 'vue'
import vueTime from 'vue-time'
Vue.component('vue-time', vueTime)
Step 5: Inside the nuxt.config.js file add the below line inside the plugins section:
nuxt.config.js
plugins: [
'@/plugins/view-ui',
{ src: '~/plugins/vue-time', ssr: false },
],
Step 6: Now to add time inside our app add the below lines inside the index.vue file in pages folder.
index.vue
<template>
<div>
<h4>GeeksforGeeks - NuxtJs Time</h4>
<vue-time :show-date="showDate" :
show-day="showDay" :
show-time="showTime"></vue-time>
</div>
</template>
<script>
export default {
data() {
return {
showDate: false,
showDay: false,
showTime: true,
options: {
hour12: true,
era: 'long',
weekday: 'long',
year: 'numeric',
month: 'numeric',
day: 'numeric'
}
}
}
}
</script>
Explanation: In the above example first, we created the vue-time file in the plugin folder and added the path in nuxt.config.js file. Now we can use the vue-time package anywhere in our app. To add the time we used the <vue-time> component in our index.vue file.
Steps to run the application: Run the below command in the terminal to run the app.
npm run dev
Output:
Similar Reads
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 DatePicker in NuxtJS ? In this article, we are going to learn how we can add a Datepicker in NuxtJs. Nuxt.js is a free and open-source web application framework based on Vue.js, Node.js, Webpack, and Babel.js. Nuxt is inspired by Next.js, which is a framework of similar purpose, based on React.js.Approach: To add our Date
2 min read
How To Set Time With Date in Moment.js? Moment.js is a powerful JavaScript library that makes it easy to work with dates and times. Sometimes, we want to set a specific time to an already existing date. For example- we have a date like "2024-08-15" and we want to set the time to "9:00 AM". Moment.js provides simple ways to do this. In thi
2 min read
How to create Time Picker in ReactJS ? Time pickers provide a simple way to select a single value from a pre-determined set. Material UI for React has this component available for us and it is very easy to integrate. We can create a Time Picker in ReactJS using the following approach:Creating React Application And Installing Module:Step
2 min read
How to Calculate Local Time in Node.js ? Calculating local time in Node.js is a common requirement for many applications, especially those that operate across multiple time zones. Node.js, with its non-blocking, event-driven architecture, makes handling dates and times relatively straightforward. This article will guide you through differe
2 min read