Creating a Windows Clock Application with HTML Application (HTA)

A clock application that displays the current time to the milliseconds can be useful sometimes.

Originally, I had created this application when I was building up my mining rig. It was very unstable as I had used a single core CPU to save on costs. Also, the CPU could run too hot due to bad thermal paste. In addition, the multiple GPUs and the drivers and mining software will cause the operating system to halt out-of-the-blue sometimes.

I wanted to create something that will keep refreshing something on the screen so I can know when to shutdown the machine and make changes to make it run more stable. I had thought of creating a small clock widget that displays the current time, with the milliseconds. This way, I can know very, very quickly when the operating system has froze, and if I'm not watching it actively and come back to it later, I will know when the freezing happened.


As my environment is Windows, I chose to use an HTML Application, because it is fairly portable and easy to make changes to. It is also easy to work with because it's running on web technologies. To explore more, here is the Wikipedia entry at HTML Application.

Here is the code, put it in a file with the extension .hta:

<hta:application border=thin maximizebutton=no innerborder=no></hta:application>

<body scroll="auto" style="padding:0;margin:0">

<table cellspacing=0 cellpadding=0 height=100% width=100%>
<tr valign=middle align=center>
<td id="time" style="font-size:1.8em;font-family:Arial;"></td>
</tr>
</table>

<script>

resizeTo(280, 100);
moveTo(0, screen.availHeight-100);

function refresh() {
    var d = new Date();
    var ampm = "AM";
    var hour = d.getHours();
    var min = d.getMinutes();
    var sec = d.getSeconds();
    var mil = d.getMilliseconds();
    if(hour == 12) ampm = "PM";
    if(hour == 0) hour = 12;
    if(hour > 12) { hour = hour - 12; ampm = "PM"; }
    if(min < 10) min = "0" + min;
    if(sec < 10) sec = "0" + sec;
    if(mil < 100) mil = "0" + mil;
    document.title = hour + ":" + min + ":" + sec + "." + mil + " " + ampm;
    document.getElementById("time").innerHTML = hour + ":" + min + ":" + sec + "." + mil + " " + ampm;
    setTimeout("refresh()", 200);
}

refresh();

</script>


Here is what it looks like when it is running:


 

Follow me! @bitcoiner

 

And vote for my witness bitcoiner!

H2
H3
H4
3 columns
2 columns
1 column
5 Comments