The following code example demonstrates how to Display a Digital Clock in JSP.

So, you can display a digital clock in JavaScript and HTML. Here is an example code.

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<script>
function startTime() {
  var today = new Date();
  var h = today.getHours();
  var m = today.getMinutes();
  var s = today.getSeconds();
  m = checkTime(m);
  s = checkTime(s);
  document.getElementById('txt').innerHTML =
  h + ":" + m + ":" + s;
  var t = setTimeout(startTime, 500);
}
function checkTime(i) {
  if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
  return i;
}
</script>
</head>

<body onload="startTime()">

<div id="txt"></div>

</body>
</html>

This code uses JavaScript to get the current time and display it in the format of hours, minutes and seconds. The startTime() function is called when the page is loaded, and it updates the time displayed on the page every 500 milliseconds. The checkTime(i) function adds a leading zero to single digit values for hours, minutes, and seconds.

Similarly, you can also write the code to display a digital clock using Java Server Pages (JSP).


Further Reading

Understanding Enterprise Java Beans

Java Practice Exercise

Princites