How to Get Current Date Time In vue js?

21-Aug-2020

.

Admin

Hi Guys,

In this example,I will explain you how to get current date in vue js?. We will show example of get current date time in vue js. If yes then i will help you to getting current date and time in vue js app. if you know to get current date in javascript or jquery then you can get same way using Date Class. we can also display current date with yyyy-mm-dd format.

it is a very simple to get current date time in vue js because we can get it using Date(). Date() will provide full date and time with timezone. so you can also make better format like yyyy-mm-dd.

Here, I will give you full example for simply get current date time in vue js as bellow.

Script Code


<script type="text/javascript">

new Vue({

el: '#app',

data: {

message:"Welcome, Please Wait...."

},

methods:{

callFunction: function () {

var currentDate = new Date();

alert(currentDate);

var currentDateWithFormat = new Date().toJSON().slice(0,10).replace(/-/g,'/');

console.log(currentDateWithFormat);

}

},

mounted () {

this.callFunction()

}

});

</script>

Full Example

<!DOCTYPE html>

<html>

<head>

<title>How to get current date time in vue js? - nicesnippets.com</title>

<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

</head>

<body>

<div id="app">

<h1>nicesnippets.com</h1>

{{ message }}

</div>

</body>

<script type="text/javascript">

new Vue({

el: '#app',

data: {

message:"Welcome, Please Wait...."

},

methods:{

callFunction: function () {

var currentDate = new Date();

alert(currentDate);

var currentDateWithFormat = new Date().toJSON().slice(0,10).replace(/-/g,'/');

console.log(currentDateWithFormat);

}

},

mounted () {

this.callFunction()

}

});

</script>

</html>

It will help you...

#Vue.Js