Most of the websites display the current date and time to the visitors in GMT/UTC. If you wish to create something similar like it for your webpage, you can make use of the below simple JavaScript code.
HTML Code:
<div id="gmt-clock" class="gmt-clock"></div>
CSS Code:
<style>
.gmt-clock {
font-family: Arial, sans-serif;
background-color: #f1f1f1;
border: 2px solid #333;
border-radius: 8px;
max-width: 300px;
padding: 5px;
text-align: center;
font-size: 14px;
box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.24);
}
</style>
JavaScript Code:
<script>
function updateGMTClock() {
const clockDiv = document.getElementById("gmt-clock");
const gmtTime = new Date().toUTCString();
clockDiv.textContent = "Time Now: " + gmtTime;
}
setInterval(updateGMTClock, 1000);
updateClock();
</script>
Final Result:
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!