Home Revolution Fullwidth › Forums › Tips & recommendations › Digital Clock using JavaScript in HTML Field
<style style="text/css">
.clock {
font-size: 4em;
}
</style>
<script>
function clock() {// We create a new Date object and assign it to a variable called "time".
var time = new Date(),
// Access the "getHours" method on the Date object with the dot accessor.
hours = time.getHours(),
// Access the "getMinutes" method with the dot accessor.
minutes = time.getMinutes(),
seconds = time.getSeconds();
document.querySelectorAll('.clock')[0].innerHTML = harold(hours) + ":" + harold(minutes) + ":" + harold(seconds);
function harold(standIn) {
if (standIn < 10) {
standIn = '0' + standIn
}
return standIn;
}
}
setInterval(clock, 1000);
</script>
<div class="clock"></div>
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.