[Question]
  [
## Display a Digital Clock
(I see there are many clock challenges, I have tried to read them all, I'm pretty sure this is unique)
Write some code that continuously updates a digital clock displayed in the format `h:m:s` where `h`, `m`, and `s` can occupy 1 or 2 characters each. The restrictions in simple terms as @BlueEyedBeast put it, I basically want it to replace the time shown.
* Newlines are not allowed
* Trailing spaces are allowed
* Other trailing characters are not allowed
* No seconds should be missed (57 -> 59 is not allowed)
* Numbers beginning with "0" are allowed, as long as they don't occupy more than 2 characters
* The code must not accept any input
* If your language can't get the current time without input, you may use for input up to 8 bytes in a standardly allowed way
* Output must be to stdout
* This is codegolf so the shortest answer wins!
**Example**
~~I'm working on a language named \*><> (starfish) because programs like this aren't possible in ><> (just wait for file i/o) . Here's a working digital clock program in it (ungolfed).~~ This program is written in [\*><>](http://esolangs.org/wiki/Starfish):
```
s":"m":"hnonon"   "ooo88888888888ooooooooooo1S
```
Note: Everything is identical to ><> in this except, s = second, m = minute, h = hour, S = sleep(100ms\*x)
This outputs:
```
14:44:31
```
Updating every 100ms until terminated.
**Disallowed Examples**
The following are not allowed:
1:
```
14:44:3114:44:32
```
2:
```
14:44:31 14:44:32
```
3:
```
14:44:31
14:44:32
```
The time must remain on the first line it was outputted with no visible trailing characters. Clearing the terminal though, would be allowed as that still wouldn't have any trailing characters.
  
[Answer]
# HTML + JS (ES6), 8 + 60 = 68 bytes
Tested in Chrome.
```
setInterval`a.innerHTML=new Date().toLocaleTimeString('fr')`
```
```
<a id=a>
```
-1 byte (@ETHProductions): Use French time format instead of `.toTimeString().slice(0,8)`
---
# HTML + JS (ES6), 8 + 62 = 70 bytes
This will work in FireFox.
```
setInterval('a.innerHTML=new Date().toLocaleTimeString`fr`',0)
```
```
<a id=a>
```
-3 bytes (@ETHProductions): Use French time format instead of `.toTimeString().slice(0,8)`
[Answer]
# Python 2, 50 bytes
(Python 2.1+ for `ctime` with no argument)
```
import time
while 1:print'\r'+time.ctime()[11:19],
```
`time.ctime()` yields a formatted string, from which the hh:mm:ss may be sliced using `[11:19]` (it remains in the same location whatever the date and time).
`print`ing the carriage return `'\r'` before the text and making the text the first item of a tuple with `,` effectively suppresses the implicit trailing `'\n'` and overwrites the previously written output.
`while 1` loops forever.
[Answer]
# Mathematica, ~~48~~ ~~41~~ ~~37~~ 28 bytes
```
Do[s=Now[[2]],∞]~Monitor~s
```
The output will be a `TimeObject`, refreshing continuously.
Looks like this: [![enter image description here](https://i.stack.imgur.com/B6qZf.jpg)](https://i.stack.imgur.com/B6qZf.jpg)
**Alternative versions**
48 bytes:
```
Dynamic@Refresh[TimeObject[],UpdateInterval->.1]
```
53 bytes:
```
Dynamic@Refresh[DateString@"Time",UpdateInterval->.1]
```
[Answer]
## Pyke, 6 bytes
```
Ctr\ J
```
[Try it here!](http://pyke.catbus.co.uk/?code=Ctr%5C+J)
I think this is valid. Replace the space character with carriage return for valid output (does not work online)
[Answer]
I see that the requirement for a non-signal UI input to stop the program has been removed. So now we can do:
# Bash + coreutils, 28
```
yes now|date -f- +$'\e[2J'%T
```
`yes` continuously outputs the string "now", once per line, into a pipe.
`date -f-` reads interprets each "now" as the current time, then outputs in the required format. The format string includes the ANSI escape sequence to clear the screen. `date` *does* output a newline after the date - I'm not sure if this disqualifies, since the screen is cleared every time anyway.
If it disqualifies, then we can use `tr` instead:
# Bash + coreutils, 31
```
yes now|date -f- +%T|tr \\n \\r
```
---
Previous Answers:
# Bash + X, 32
```
xclock -d -update 1 -strftime %T
```
Unfortunately this can only update every second. If that disqualifies, then we can do this instead:
# Bash + coreutils, 43
```
until read -t0
do printf `date +%T`\\r
done
```
[Answer]
## [QBIC](https://drive.google.com/drive/folders/0B0R1Jgqp8Gg4cVJCZkRkdEthZDQ), 6 bytes
```
{_C?_d
{      Starts a DO-loop
 _C    CLS
   ?   PRINT
    _d TIME$
```
Constantly clears the screen and prints the system time in the format `22:03:41`.
[Answer]
# PHP, 28 bytes
```
for(;;)echo date("\rH:i:s");
```
The `date` function prints everything literally that it doesn´t recognize.
`\r` is the carriage return, sets the cursor to the first column.
Run with `-r`.
[Answer]
# Clojure, ~~150~~ ~~136~~ 141 bytes
## V3: 141 bytes :(
+5 bytes to fix a bug. Since the times aren't zero padded, the clock can "shrink" and expand when the time changes. It was "smearing" when it shrunk because the last digit was no longer being cleared. Fixed it by adding some spaces at the end to ensure everything is being overwritten.
```
#(while true(flush)(print(str(apply str(repeat 9"\b"))(.format(java.text.SimpleDateFormat."H:m:s")(java.util.Date.))"   "))(Thread/sleep 99))
```
## V2: 136 bytes
```
#(while true(flush)(print(str(apply str(repeat 9"\b"))(.format(java.text.SimpleDateFormat."H:m:s")(java.util.Date.))))(Thread/sleep 99))
```
-14 bytes by switching to using `SimpleDateFormat` to format the date. Still huge.
## V1: 150 bytes
```
#(while true(let[d(java.util.Date.)](flush)(print(str(apply str(repeat 9 "\b"))(.getHours d)":"(.getMinutes d)":"(.getSeconds d)))(Thread/sleep 100)))
```
I realized I'm probably using the worst way possible to get the date. Definitely room for improvement here.
Ungolfed:
```
(defn -main []
  (while true
    (let [d (java.util.Date.)]
      (flush)
      (print
        (str
          (apply str (repeat 9 "\b"))
          (.getHours d)":"(.getMinutes d)":"(.getSeconds d)))
      (Thread/sleep 100))))
```
[Answer]
# SmileBASIC 3.3.2, 38 bytes
```
@L?TIME$;" ";
GOTO@L
```
UTF-16 sucks :(
Anyway, this repeatedly prints the local time in HH:MM:SS with a space after it, no newline afterward. It doesn't update every second though, it just repeatedly prints forever.
[Answer]
## C, ~~134~~ ~~116~~ ~~89~~ ~~80~~ ~~76~~ ~~75~~ 73 bytes
```
main(n){for(;time(&n);)printf("\r%02d:%02d:%02d",n/3600%24,n/60%60,n%60);}
---- Old versions:
main(n){for(;;)n=time(0),printf("\r%02d:%02d:%02d",n/3600%24,n/60%60,n%60);}
n;main(){for(;;)n=time(0),printf("\r%02d:%02d:%02d",n/3600%24,n/60%60,n%60);}
---- 
n;main(){for(;;)n=time(0),printf("\r%02d:%02d:%02d",n/3600%24,n/60%60,n%60);}
----
Saved 9 more bytes thanks to @nmjcman101 again:
n;main(){for(;;)n=time(0),printf("\r%02d:%02d:%02d",(n/3600)%24,(n/60)%60,n%60);}
----
Saved 27 bytes thanks to @nmjcman101
n,b[9];main(){for(;;){n=time(0);strftime(b,9,"%H:%M:%S",localtime(&n));printf("\r%s",b);}}
----
I figured out I don't need to put `#include<stdio.h>` into the file :)
#include<time.h>
main(){for(;;){time_t n=time(0);char b[9];strftime(b,9,"%H:%M:%S",localtime(&n));printf("\r%s",b);}}
----
#include<time.h>
#include<stdio.h>
main(){for(;;){time_t n=time(0);char b[9];strftime(b,9,"%H:%M:%S",localtime(&n));printf("\r%s",b);}}
```
[Answer]
# Bash + watch, 19 bytes
*watch* is not a part of *coreutils*, but is available out of the box on virtually every Linux distro.
**Golfed**
```
watch -tn1 date +%T
```
[Try it online !](https://goo.gl/5Ayb7t)
[Answer]
# [MATL](https://github.com/lmendo/MATL), 11 bytes
```
`XxZ'13XODT
```
Infinite loop that clears the screen and prints the time in the specified format.
You can try it at [MATL Online!](https://matl.io/?code=%60XxZ%2713XODT&inputs=&version=19.5.1). This compiler is experimental; if it doesn't work refresh the page and press "Run" again.
[Answer]
# WinDbg, 73 bytes
```
.do{r$t0=0;.foreach(p {.echotime}){r$t0=@$t0+1;j8==@$t0'.printf"p \r"'}}1
```
It continually updates a line with the current time until the user presses Ctrl+Break.
How it works:
```
.do                          * Start do-while loop
{
    r$t0 = 0;                * Set $t0 = 0
    .foreach(p {.echotime})  * Foreach space-delimited word in a sentence like "Debugger (not 
    {                        * debuggee) time: Mon Dec  5 14:08:10.138 2016 (UTC - 8:00)"
        r$t0 = @$t0+1;       * Increment $t0
        j 8==@$t0            * If $t0 is 8 (ie- p is the current time)
        '
            .printf"p \r"    * Print p (current time) and \r so the next print overwrites
        '
    }
} 1                          * Do-while condition: 1, loop forever
```
Sample output (well, you get the idea):
```
0:000> .do{r$t0=0;.foreach(p {.echotime}){r$t0=@$t0+1;j8==@$t0'.printf"p \r"'}}1
14:10:12.329
```
[Answer]
# C#, 82 bytes
```
()=>{for(;;)Console.Write(new string('\b',8)+DateTime.Now.ToString("HH:mm:ss"));};
```
Anonymous method which constantly overwrites 8 characters with new output. Can be made 1 byte shorter if modifying to accept a dummy parameter (`z=>...`).
Full program:
```
using System;
public class Program
{
    public static void Main()
    {
        Action a =
        () =>
        {
            for (;;)
                Console.Write(new string('\b', 8) + DateTime.Now.ToString("HH:mm:ss"));
        };
        a();
    }
}
```
[Answer]
## C#, 65 bytes
```
()=>{for(;;)Console.Write("\r"+DateTime.Now.ToLongTimeString());};
```
Works by overwriting the same line within an endless loop
[Answer]
# Powershell, 39 bytes
```
for(){write-host -n(date -F h:m:s`0`r)}
```
Because I dislike using cls in Powershell. From briantist's post @<https://codegolf.stackexchange.com/a/102450/63383>
[Answer]
# Pascal, 61 bytes
```
uses sysutils;begin while 1=1do write(#13,timetostr(now))end.
```
Free pascal has nice time routines in SysUtils unit. Ungolfed:
```
uses
  sysutils;
begin
  while 1=1 do
    write(#13, timetostr(now));
end.
```
[Answer]
# Commodore BASIC (CBM/PET, C64, C128, VIC-20, C16/+4), 64 ~62 BASIC bytes (tokens), 64 62 PETSCII characters with keyword abbreviations
```
?"{CLEAR}":FORI=0TO1:?"{HOME}"LEFT$(TI$,2)":"MID$(TI$,3,2)":"RIGHT$(TI$,2):I=0:NEXT
```
**Edit** I realised that this is what I would call a *zero liner*, or in other words, it does not require a line number to run, so I've taken this out. Once you break it though, you need to type it in again.
**Changes** Line numbers in Commodore BASIC take up I think at least two bytes (though I need to check), so by actual byte count is an estimation, however, removing the line number and using the `LEFT$` command for the first two digits, rather than the `MID$` command, has shaved off two whole characters from this.
Some notes: if you are entering this on a Commodore C64 then you will need to use keyword abbreviations (see the screen shot below). Some other Commodore 8-bits, like the C128 and VIC-20, accept more than 80 characters entered per line, but to be sure, use the keyword abbreviations anyway.
To set the time first, use `TI$="112233"` as `HHMMSS` format as 24 hours (`000000` being midnight).
## How it works
`TI$` is a system variable which fairly accurately keeps time. 8 BIT Show and Tell explores this in some depth in [this YouTube video](https://youtu.be/VkabHdR15xs) and is well worth a watch if you are interested.
An unbroken loop is set with resetting the `I` variable per iteration by setting it to `0`. We then use the `MID$` and `RIGHT$` function to print out each relevant time segment, being `HH:MM:SS`. A list of BASIC keywords can be found [here](https://www.c64-wiki.com/wiki/BASIC).
[![Display a Digital Clock, Commodore C64](https://i.stack.imgur.com/zBhRD.png)](https://i.stack.imgur.com/zBhRD.png)
[Answer]
# Vim, 26 bytes
```
qqS<C-r>=strftime("%T")<CR><esc>@qq@q
```
This creates a recursive macro (e.g. an eternal loop) that deletes all the text on the current line and replaces it with the current time.
[Answer]
# Pyth - 28 bytes
Kinda longish, because pyth has no strftime.
```
#p+"\r"j\:m.[`02`dP>4.d2.d.1
```
[Answer]
# Groovy, 45 characters
```
for(;;)print(new Date().format("\rHH:mm:ss"))
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
13Ọ7ŒTȮß
13Ọ        chr(13), carriage return
   7ŒT     time string, which extends the previous character
      Ȯ    print
       ß   call the whole link again
```
[Try it online!](http://jelly.tryitonline.net/#code=MTPhu4w3xZJUyK7Dnw)
The carriage return doesn't work online, and I can't get the interpreter to work, so its kinda untested, but it works as expected when I use printable characters in place of the CR.
[Answer]
# ForceLang, 123 bytes
```
def s set
s d datetime
s z string.char 8
s z z.repeat 16
label 1
io.write z
io.write d.toTimeString d.now()
d.wait 9
goto 1
```
`datetime.toTimeString` is backed in the reference implementation by Java's `DateFormat.getTimeInstance()`, which is locale-dependent, so you can set your default system locale to one that uses 24-hour time.
[Answer]
# PowerShell, ~~30~~ ~~28~~ ~~24~~ 20 bytes
Changed my computer's region to Germany based on [raznagul](https://codegolf.stackexchange.com/users/42502/raznagul)'s comment to save 4 bytes. :)
```
for(){date -F T;cls}
```
### Previous version that works in all locales.
```
for(){date -F h:m:s;cls}
```
[Answer]
# Java, 67 bytes
```
for(;;)System.out.print("\r"+java.time.LocalTime.now()+"\b\b\b\b");
```
We loop infinitely, grabbing the current time and outputting to screen. The quad backspace is for easy formatting, because otherwise we'd have to do something like this:
```
for(;;)System.out.print("\r" + java.time.LocalTime.now().truncatedTo(java.time.temporal.ChronoUnit.SECONDS));
```
[Answer]
# tcl, 69 bytes
```
while 1 {puts -nonewline \r[clock format [clock seconds] -format %T]}
```
[Try it here!](http://www.tutorialspoint.com/execute_tcl_online.php?PID=0Bw_CjBb95KQMUkdTRkhVUDRFbkU)
[Answer]
## C 65 (prev 64) bytes
Guaranteed to work on Linux machine. :)
@Marco Thanks!
```
f(){while(1){system("date +%T");usleep(100000);system("clear");}}
```
[Answer]
# SmileBASIC, 14 bytes
```
CLS?TIME$EXEC.
```
`CLS` clears the screen, `? TIME$` prints the current time, and `EXEC 0` runs the code that's in slot 0.
It's a bit flickery, but there's nothing in the reqirements about that, so it should be fine.
Format is `HH:MM:SS` 24 hour time :(
[Answer]
# x86-16 machine code, IBM PC DOS, ~~71~~ 69 bytes
Binary:
```
00000000: b81c 35cd 2153 06ba 1901 e806 00b4 08cd  ..5.!S..........
00000010: 211f 5ab8 1c25 cd21 c3b4 2ccd 218a c5e8  !.Z..%.!..,.!...
00000020: 0800 91e8 0400 8ac6 b2ff d40a 0d30 3086  .............00.
00000030: e0cd 2986 e0cd 2984 d27c 05b0 3acd 29c3  ..)...)..|..:.).
00000040: b00d cd29 cf                             ...).
```
Listing:
```
B8 351C         MOV  AX, 0351CH             ; AL = 1CH, AH = 35H 
CD 21           INT  21H                    ; get interrupt vector for 1CH into ES:BX
53              PUSH BX                     ; save old vector
06              PUSH ES                     ; save old segment
BA 011D R       MOV  DX, OFFSET GET_TIME    ; DX = interrupt vector of time proc 
E8 0117 R       CALL SET_VECT               ; setup new vector
B4 08           MOV  AH, 8                  ; DOS read char from stdin without echo
CD 21           INT  21H                    ; wait for user to press the "any key"
1F              POP  DS                     ; restore old segment
5A              POP  DX                     ; restore old vector
            SET_VECT: 
B8 251C         MOV  AX, 0251CH             ; AL = 1CH, AH = 25H 
CD 21           INT  21H                    ; set interrupt vector from DS:DX
C3              RET                         ; return to DOS 
            GET_TIME: 
B4 2C           MOV  AH, 2CH                ; get DOS time 
CD 21           INT  21H                    ; CH = hour CL = minute DH = second 
8A C5           MOV  AL, CH                 ; display hour: AL = CH 
E8 012E R       CALL OUT_TIME               ; write time
91              XCHG AX, CX                 ; display minute: AL = CL 
E8 012E R       CALL OUT_TIME               ; write time
8A C6           MOV  AL, DH                 ; display second: AL = DH 
B2 FF           MOV  DL, -1                 ; set DL to -1 so doesn't display ':' 
            OUT_TIME:    
D4 0A           AAM                         ; BCD convert: AL = AL % 10, AH = AL / 10 
0D 3030         OR   AX, '00'               ; ASCII convert 
86 E0           XCHG AH, AL                 ; endian convert 
CD 29           INT  29H                    ; write tens 
86 E0           XCHG AH, AL                 ; swap digits 
CD 29           INT  29H                    ; write ones 
84 D2           TEST DL, DL                 ; when DL = -1, it is seconds digit 
7C 05           JL   DONE_TIME              ; if last number, write CR not ':'
B0 3A           MOV  AL, ':'                ; write ':'
CD 29           INT  29H 
C3              RET                         ; return from near call
            DONE_TIME: 
B0 0D           MOV  AL, 0DH                ; carriage return 
CD 29           INT  29H                    ; move cursor back to beginning of line
CF              IRET                        ; return from interrupt 
```
A standalone PC DOS executable COM program. Uses DOS to hook the hardware timer interrupt which calls the program every 18.2ms to update the clock on the screen. Exits when any key is pressed.
Runtime:
[![enter image description here](https://i.stack.imgur.com/GkdLi.gif)](https://i.stack.imgur.com/GkdLi.gif)
(A key was hit after 5 seconds, exiting the program)
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 8 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
i@OqK¤¯8
```
[Test it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=aUBPcUukrzg)
```
i@OqK¤¯8
i            :Every 0 milliseconds
 @           :Run the following function
  Oq         :Replace the output with
    K        :Date object
     ¤       :Convert to time string
      ¯8     :Slice to the 8th character
```
]