How to get current date time in vue js?

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Hello Dev’s
Hope all are feeling okay. Today in this tutorial I will show you how to get current date time in vue js app. Do you want get current date time in your vue js app. If yes then I think you are in right place. I will help you to getting current datetime in your vue js app. If you know how to get current date by using javascript or jquery then you can also get same way by using Date Class. We can also display current date with by this yyyy-mm-dd format.

I hope it is a very simple and easy to get current datetime in vue js app. Because we can get it just by using Date() function. Date() function will provide us full date and time with the time zone. So we can also make it in better format as like yyyy-mm-dd.

Now in bellow I will give you very a small and simple example. Now you can easily understand how can we display current date with time in vue js app.

Example:

<!DOCTYPE html>
<html>
<head>
    <title>How to get current date time in vue js? - Codingspoint.com</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
   
<div id="app">
    {{ message }}
</div>
  
</body>
  
<script type="text/javascript">
 new Vue({
    el: '#app',
    data: { 
          message:"Welcome, Please Wait...."
      },
      methods:{
        callFunction: function () {
   
            var currentDate = new Date();
            console.log(currentDate);
  
            var currentDateWithFormat = new Date().toJSON().slice(0,10).replace(/-/g,'/');
            console.log(currentDateWithFormat);
     
        }
    },
    mounted () {
      this.callFunction()
    }
 });
    
</script>
</html>

Read Also : How to Install Vue JS in Laravel 8 ?

thanks for reading. I hope it will help you. Also you can follow us on Facebook

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →