<script>function foo(num) { return num < 10 ? '0' + num : num; } var date = new Date(); document.write( foo( date.getHours() ) + ':' + foo( date.getMinutes() ) + ':' + foo( date.getSeconds() ) );</script>