Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


Screenshot showing clock next to search box.


This user script adds a clock on the user bar next to the search box. When visiting a Stack Exchange site I sometimes like to know the current Stack Exchange time. This clock calculates the time locally so it isn't "server time" but it is close enough for me.

The clock display is formatted as a link to the "current time" query on Wolfram Alpha so that it's styled the same as the other items on the user bar.

It should work on any site in the Stack Exchange network, except for the network hub site at which uses a different template.


Released into the public domain.



// ==UserScript==
// @name           Stack Exchange Clock
// @namespace
// @description    Display UTC clock on Stack Exchange sites.
// @include*
// @include*
// @include*
// @include*
// @include*
// @include*
// @include        http://**
// @include        http://**
// @include        http://**
// @include        http://**
// @include        http://**
// @include        http://**
// ==/UserScript==

/* Generate the current time string in UTC. */
function get_time() {
    var today = new Date();
    var h = today.getUTCHours();
    var m = zero_pad(today.getUTCMinutes());
    var s = zero_pad(today.getUTCSeconds());

    return h + ":" + m + ":" + s + " UTC";

/* Add a leading zero if required. */
function zero_pad(number) {
    if (number >= 0 && number < 10) {
        return "0" + number;
    return number;

/* Update the time display. */
function update_time() {
    var stamp = document.getElementById('utc-clock');
    stamp.innerHTML = get_time();

/* Generate the HTML element for the stamp and insert,
   wrap time in a link to fit in with the footer menu. */
var time_url = "";
var time_block = document.createElement("span");
var inner_s = "<span class='lsep'>|</span> ";
inner_s += "<a id='utc-clock' title='Current Time' href='";
inner_s += time_url + "'>" + get_time() + "</a>";
time_block.innerHTML = inner_s;

var target = document.getElementById('hlinks-custom');
if (target) {
    target.parentNode.insertBefore(time_block, target.firstSibling);

var f = function() { update_time(); }
window.setInterval(f, 1000);
share|improve this question
Can you post an install link for convenience? – Dennis Williamson Feb 19 '11 at 20:13
Here's an install link. I uploaded it to – Thomas Ward Feb 4 '12 at 21:06

You must log in to answer this question.

Browse other questions tagged .