Vue.Js get current timestamp


We can use Date().getTime() method to get the current timestamp in vue.js. Here in this tutorial, we are going to explain how you can get current timestamp in UNIX. You can also use our online editor to edit and run the code online.


Vue.Js get current timestamp Example

You can get current UNIX timestamp in Vue.js simply as below-

Example:

<div id="app">
	<p>Result = {{result}}</p>
	<button @click="myFunction()">Click Me</button>
</div>
<script>
 new Vue({
 el: '#app',
  
  data: {
	  result:''
  },  
   methods:{
    myFunction: function () {
	 this.result = Math.round(+new Date()/1000);// unix timestamp
    }
   }
});
</script> 

Try it »

Output of above example-

Vue.Js get current timestamp

Advertisements

Add Comment

📖 Read More