How to make a Digital Clock for Website ?
SEO Help and Tips
How to make a Digital Clock for Website ?
Here is example code of Digital Clock:
<head>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
}
#clock {
font-size: 48px;
}
</style>
</head>
<body>
<div id="clock">12:00:00</div>
<script>
function updateClock() {
const now = new Date();
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
const timeString = `${hours}:${minutes}:${seconds}`;
document.getElementById('clock').textContent = timeString;
}
// Update the clock every second
setInterval(updateClock, 1000);
// Initialize the clock on page load
updateClock();
</script>
</body>
Python:
import tkinter as tk
import time
class ColorfulClock:
def __init__(self, root):
self.root = root
self.root.title("Colorful Digital Clock")
self.time_label = tk.Label(root, text="", font=("Helvetica", 48))
self.time_label.pack(pady=20)
self.update_time()
def update_time(self):
current_time = time.strftime("%H:%M:%S")
self.time_label.config(text=current_time)
self.time_label.after(1000, self.update_time)
if __name__ == "__main__":
root = tk.Tk()
clock = ColorfulClock(root)
root.mainloop()
Comments
Post a Comment
Thanks for your Comments.