Simple Clock: Text
In this post, we create a simple clock app.
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to JS Bin</title>
</head>
<body>
<h1 id="clock"> Time </h1>
</body>
</html>
We are going to just replace the text inside the H1 with the id clock.
CSS:
h1 {
position: absolute;
top: 50%;
left:50%;
transform: translateX(-50%);
}
This is just a couple of rules to center the H1
Javascript:
var readyStateCheckInterval = setInterval(function() {
if (document.readyState === "complete") {
init();
clearInterval(readyStateCheckInterval);
}
}, 100);
function init() {
setInterval(updateTime, 1000);
}
function updateTime() {
var clock = document.getElementById('clock');
var date = formatDate(new Date());
clock.innerHTML = date;
}
function formatDate(d) {
var hh = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds();
var dd = "AM";
var h = hh;
if (h >= 12) {
h = hh-12;
dd = "PM";
}
if (h === 0) {
h = 12;
}
m = m<10?"0"+m:m;
s = s<10?"0"+s:s;
return h + ":" + m + ":" + s + " " + dd;
}
The this will get the time from a Date object, format it to a 12 hour format that includes seconds, and will update the text of the H1.
The manifest is very similar to the one from Hello, Firefox.
{
"name": "Simple Clock",
"description": "Simple Text Based Clock",
"launch_path": "/index.html",
"icons": {
"128": "/img/ic_simple_clock.png"
}
}
Here is the icon.
TODO: Show how to install a hosted application
Recent Blog Posts
- 13 Apr 2026 Your intuition of LLM token usage might be wrong
- 11 Feb 2026 Locust Load Testing and Markov Chains
- 20 Jan 2026 I love the old man minimap in VS Code
- 03 Jan 2026 On Resurrecting a 12 year old blog
- 09 Oct 2014 Updating a forked Git repo
- 06 Oct 2014 ADB access to remote server from local usb
- 30 Mar 2014 Bug Progress: Day 2
- 27 Mar 2014 Building the Emulator
- 11 Mar 2014 Simple Notes: Edit Notes
- 10 Mar 2014 Simple Notes: Hidden Notes Fix