Skip to content

Instantly share code, notes, and snippets.

@RashidJorvee
Created April 23, 2020 12:16
Show Gist options
  • Save RashidJorvee/b2728f4ca11d295c371f547c5cdc1d05 to your computer and use it in GitHub Desktop.
Save RashidJorvee/b2728f4ca11d295c371f547c5cdc1d05 to your computer and use it in GitHub Desktop.
Current date using JavaScript new Date()
<html>
<body>
<h2>Current date using JavaScript new Date()</h2>
<p id="demo"></p>
<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>
<script>
//Create object of Date
var today = new Date();
//using getDate function get the date from Date object
document.getElementById("demo1").innerHTML = day = today.getDate();
//using getMonth function get the month from Date object
document.getElementById("demo2").innerHTML = month = today.getMonth();
//using getYear function get the year from Date object
document.getElementById("demo3").innerHTML = year = today.getFullYear();
//Now concatinate all those variables in create a format whatsoever you want.
document.getElementById("demo").innerHTML = year.toString() + month.toString() + day.toString();
</script>
</body>
</html>
@RashidJorvee
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment