Skip to content

Instantly share code, notes, and snippets.

@nijatmursali
Created January 20, 2022 20:51
Show Gist options
  • Save nijatmursali/893c234ee8e1443bca4460cdbbcdb710 to your computer and use it in GitHub Desktop.
Save nijatmursali/893c234ee8e1443bca4460cdbbcdb710 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Clock</title>
</head>
<body>
<div id="time">00:00:00</div>
</body>
<script type="text/javascript">
function start() {
let time = new Date();
let hours = time.getHours();
let mins = time.getMinutes();
let seconds = time.getSeconds();
if (seconds.toString().length == 1) {
seconds = "0" + seconds.toString();
}
if (mins.toString().length == 1) {
mins = "0" + mins.toString();
}
if (hours.toString().length == 1) {
hours = "0" + hours.toString();
}
document.getElementById("time").innerHTML = hours.toString() + ":" + mins.toString() + ":" + seconds.toString();
setTimeout(() => {
start()
}, 1);
}
start();
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment