Vue.Js Get Current Date time


Vue.Js Get Current Date time We can use native JavaScript Date function to get current date and time in Vue.js. Here in this article we are going to explain how to get current datetime in Vue.Js using native JavaScript Date Function.


Vue.Js Get Current Date time Example

You can get the current date time using native JavaScript date Function simply as below-

Vue.Js Get Current Date time Example:

<!DOCTYPE html>
<html>
<body>

<p id="dateDemo"></p>

<script>
document.getElementById("dateDemo").innerHTML = Date();
</script>

</body>
</html>

Try it »

If you run the above example it will produce output something like this-

Get Current Date in YYYY-MM-DD Format

You can get in YYYY-MM-DD format simply as below-

Vue.Js Get Current Date time Example:

<!DOCTYPE html>
<html>
<body>

<p id="dateDemo"></p>

<script>
var myDate = new Date();
var month = ('0' + (myDate.getMonth() + 1)).slice(-2);
var date = ('0' + myDate.getDate()).slice(-2);
var year = myDate.getFullYear();
var formattedDate = year + '/' + month + '/' + date;
document.getElementById("dateDemo").innerHTML = formattedDate;
</script>

</body>
</html>

Try it »

If you run the above example it will produce output something like this-

Vue.js get currnet date in y-m-d format


Advertisements

Add Comment

📖 Read More