Javascript countdown timer

Nothing too fancy here, but potentially useful to people. The other day a forum I maintain needed a way for users to add a countdown timer to their posts, so I wrote this bit of Javascript and added it as a new BBCode. Feel free to use it and share it.

The help text

[countdown]year, month, day, hour, min, sec[/countdown]

The date/time must be specified in UTC (GMT). sec is optional.

The BBCode

[countdown]{SIMPLETEXT}[/countdown]

The replacement text

<script type="text/javascript">
(function() {
    var end_time = new Date( Date.UTC( {SIMPLETEXT} ) );
    var countdown_element;

    var els = document.getElementsByClassName("countdown_timer");
    for (var i=0, max=els.length; i < max; i++) {
        if ( ! /has_timer/.test(els[i].className) ) {
            countdown_element = els[i];
            countdown_element.className += " has_timer";
            break;
        }
    }

    var update = function() {
        var now = new Date();
        if (now.getTime() < end_time.getTime()) {
            var time_left = end_time.getTime() – now.getTime();
            time_left = Math.floor(time_left / 1000);

            var secs = time_left % 60;
            time_left = Math.floor(time_left / 60);

            var mins = time_left % 60;
            time_left = Math.floor(time_left / 60);

            var hours = time_left;

            var time_string = "";
            if (hours < 10) {
                time_string += "0";
            }
            time_string += hours + ":";
            if (mins < 10) {
                time_string += "0";
            }
            time_string += mins + ":";
            if (secs < 10) {
                time_string += "0";
            }
            time_string += secs;

            countdown_element.innerHTML = time_string;
        } else {
            countdown_element.innerHTML = "time expired";
        }
    }
    setInterval(update, 1000);
}
)();
</script>