x
 
1
<!DOCTYPE html>
2
<title>My Example</title>
3
4
5
<time id="time"></time>
6
7
<script>
8
  /* 
9
  Create a JavaScript Date object for the current date and time,
10
  then extract the desired parts, then join them again in the desired format.
11
  */
12
  var currentTime = new Date(),
13
      hours = currentTime.getHours(),
14
      minutes = currentTime.getMinutes();
15
  
16
  // Add a leading zero if needed
17
  if (minutes < 10) {
18
    minutes  = "0" + minutes; 
19
  }
20
  
21
  // Join the parts
22
  time = hours + ":" + minutes;
23
      
24
  // Output the result to the above HTML element
25
  document.getElementById("time").innerHTML = time;
26
</script>