Created
April 23, 2020 12:16
-
-
Save RashidJorvee/b2728f4ca11d295c371f547c5cdc1d05 to your computer and use it in GitHub Desktop.
Current date using JavaScript new Date()
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(); | |
//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> |
Author
RashidJorvee
commented
Apr 23, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment