function getDate() {
var currentDate = new Date();
document.getElementById("demo").innerHTML =
[
currentDate.getFullYear(),
currentDate.getMonth() + 1,
currentDate.getDate()
].join("/") +
" " +
[
currentDate.getHours(),
currentDate.getMinutes(),
currentDate.getSeconds()
].join(":");
}
<!DOCTYPE html>
<html>
<body>
<h2>Function to diplay time</h2>
<button type="button"
<!-- begin snippet: js hide: false console: true babel: false -->
onclick="document.getElementById('demo').innerHTML = Date()">
Click me</button>
<p id="demo"></p>
</body>
</html>
This question already has answers here :
Closed 2 years ago .
I just want to display the default format to like this yyyy/mm/dd hh:mm:ss
rather than Wed Mar 04 2020 18:18:21 GMT+0530 (India Standard Time)
as default format.
<!DOCTYPE html>
<html>
<body>
<h2>Function to diplay time</h2>
<button type="button"
onclick="document.getElementById('demo').innerHTML = Date()">
Click me</button>
<p id="demo"></p>
</body>
</html>
This is not what I am looking for.
I just simply want to format the output as I mentioned above. This is the output format which I want yyyy/mm/dd hh:mm:ss
please check this is not working anyway.