Madras Academy
Home / Blog / html / Create a Live Clock with Multiple Time Zones Using HTML, CSS, and JavaScript
html

Create a Live Clock with Multiple Time Zones Using HTML, CSS, and JavaScript

March 12, 2025 admin 3 min read

Are you looking to add a real-time clock that displays multiple time zones to your website? In this step-by-step guide, you’ll learn how to create a live digital clock using HTML, CSS, and JavaScript. This clock automatically updates every second and shows the current time in various locations, including local time, New York, London, and Tokyo.

This tutorial is perfect for international websites, remote teams, or anyone who wants to keep track of different time zones in real time!


๐Ÿš€ What Youโ€™ll Learn

โœ… How to display a real-time digital clock using JavaScript ๐Ÿ•ฐ๏ธ
โœ… How to format time correctly for different time zones ๐ŸŒŽ
โœ… Using CSS to style the clock for a modern, sleek design ๐ŸŽจ
โœ… How JavaScriptโ€™s Date API dynamically fetches the time โฒ๏ธ
โœ… How to create an auto-updating clock for a smooth user experience โŒ›


๐Ÿ“Œ Step-by-Step Guide

1๏ธโƒฃ HTML Structure

First, we create a simple HTML file with a structured layout to display multiple time zones.


๐Ÿ“„ Code: HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Live Clock with Time Zones</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="clock-container">
        <h2>Live Time Zones</h2>
        <div class="clock" id="localTime">Local Time: --:--:--</div>
        <div class="clock" id="newYorkTime">New York: --:--:--</div>
        <div class="clock" id="londonTime">London: --:--:--</div>
        <div class="clock" id="tokyoTime">Tokyo: --:--:--</div>
    </div>
    <script src="script.js"></script>
</body>
</html>

๐ŸŽจ Code: CSS (styles.css)

The CSS ensures that the clock looks modern and clean with a responsive layout.

body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    flex-direction: column;
}
.clock-container {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    text-align: center;
    width: 350px;
}
h2 {
    font-size: 28px;
    color: #007BFF;
    background: #E3F2FD;
    padding: 10px;
    border-radius: 5px;
}
.clock {
    font-size: 24px;
    font-weight: bold;
    margin: 10px 0;
}

๐Ÿ› ๏ธ Code: JavaScript (script.js)

The JavaScript code dynamically updates the clock every second.

function updateTime() {
    const now = new Date();
    document.getElementById("localTime").textContent = "Local Time: " + now.toLocaleTimeString();
    
    const newYorkTime = new Date().toLocaleTimeString("en-US", { 
        timeZone: "America/New_York", 
        hour12: true, 
        hour: '2-digit', 
        minute: '2-digit', 
        second: '2-digit' 
    });
    document.getElementById("newYorkTime").textContent = "New York: " + newYorkTime;
    
    const londonTime = new Date().toLocaleTimeString("en-GB", { 
        timeZone: "Europe/London", 
        hour12: true, 
        hour: '2-digit', 
        minute: '2-digit', 
        second: '2-digit' 
    });
    document.getElementById("londonTime").textContent = "London: " + londonTime;
    
    const tokyoTime = new Date().toLocaleTimeString("ja-JP", { 
        timeZone: "Asia/Tokyo", 
        hour12: true, 
        hour: '2-digit', 
        minute: '2-digit', 
        second: '2-digit' 
    });
    document.getElementById("tokyoTime").textContent = "Tokyo: " + tokyoTime;
}

setInterval(updateTime, 1000);
updateTime();

๐ŸŽฏ Why This Project Is Useful

โœ… Enhances user experience with real-time updates
โœ… Useful for global users tracking multiple time zones
โœ… Simple yet effective example of JavaScriptโ€™s Date API
โœ… Can be integrated into websites, dashboards, and business applications


๐Ÿ“Œ Live Demo & GitHub Repository

๐Ÿ”— Live Demo:


๐Ÿ’ป GitHub Source Code: View on GitHub


๐ŸŽฅ Watch the Full Tutorial

Want a detailed walkthrough? Watch the full tutorial on Madras Academyโ€™s YouTube channel:

๐Ÿ“บ Live Clock with Multiple Time Zones Tutorial

๐Ÿ“Œ Donโ€™t forget to like, comment, and subscribe to Madras Academy for more exciting web development tutorials! ๐Ÿš€


๐Ÿ”ฅ Stay Updated with More Web Development Tips

Follow us for more HTML, CSS, and JavaScript tutorials:

๐Ÿ“Œ #HTML #CSS #JavaScript #LiveClock #RealTime #TimeZones #WebDevelopment #FrontendDevelopment #Coding #TechTutorial #DigitalClock ๐Ÿ•’๐Ÿ”ง

๐Ÿš€ Start building your own real-time clock today! Let me know in the comments if you have any questions. Happy coding! ๐Ÿ’ป๐ŸŽ‰

RECOMMENDED COURSES

Continue learning with Madras Academy.

Here are a few courses selected from our current catalog.

Browse All Courses
JAVA

Java Programming & OOP

Learn Java from fundamentals through object-oriented design, collections, exceptions and database connectivity.

10 Weeks Beginner โ†’ Intermediate
JavaOOPCollections
W WhatsApp