Created
April 24, 2020 17:54
-
-
Save RashidJorvee/8af8c42d2a0268d7ff08853578c16e9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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().toString().padStart(2, "0"); | |
//using getMonth function get the month from Date object | |
document.getElementById("demo2").innerHTML = month = (today.getMonth() + 1).toString().padStart(2, "0") | |
//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> |
Author
RashidJorvee
commented
Apr 24, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment