0

Can any body help me, the button replace hours and minutes (HH:MM) onclick.

<button id="pressbtn1" onclick="getElementById('pressbtn1').innerHTML=Date()">Press</button>

Kheng Yung
  • 27
  • 4
  • Welcome to Stack Overflow! Please visit the [help] to see what and [ask]. HINT: Post effort and CODE. – mplungjan Sep 22 '19 at 17:04
  • 1. it is document.getElementById but it is not needed when it is inline. 2. Please search for hh mm and you would have found `var d = new Date(); var n = d.toLocaleTimeString();` to which you add `.slice(0,-3);` – mplungjan Sep 22 '19 at 17:05

1 Answers1

1

Use .getHours() and .getMinutes() like...

<html>
<button id="pressbtn1" onClick="show()">Press</button>
<script>
 function show()
 {
  var today = new Date();
  var h = today.getHours();
  var m = today.getMinutes();
document.getElementById("pressbtn1").innerHTML  = h+":"+m;
}
</script>
</html>
Dem Pilafian
  • 5,625
  • 6
  • 39
  • 67
RAKTIM BANERJEE
  • 304
  • 4
  • 12