Challenge

You must output the current time continuously (until cancelled by an interrupt), once every second, by any of the following means:

• It must be in 24-hour or AM/PM format.
• If it is the former, it must be spaced out with colons (i.e. 15:47:36).
• If it is the latter, it must be spaced out with colons and have the AM/PM following (i.e. 3:47:36 PM)
• It may be pulled from the internet.
• It may be the system time.
• It must output any naturally accessible form of output which supports text that you choose.
• Output may have extra information aside of the time in it, but you must guarantee one, and only one, output of time per second.
• The continuous output must be a second apart - if you choose to wait until the second changes between outputs, that is fine. If you wait a second between each output, that is perfectly acceptable, despite the eventual loss of accuracy.

Since this is a catalog, languages created after this challenge are allowed to compete. Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language. Other than that, all the standard rules of must be obeyed. Submissions in most languages will be scored in bytes in an appropriate preexisting encoding (usually UTF-8).

Catalog

The Stack Snippet at the bottom of this post generates the catalog from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

## Language Name, N bytes


where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

## Ruby, <s>104</s> <s>101</s> 96 bytes


If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

## Perl, 43 + 2 (-p flag) = 45 bytes


You can also make the language name a link which will then show up in the snippet:

## [><>](http://esolangs.org/wiki/Fish), 121 bytes


var QUESTION_ID=65020,OVERRIDE_USER=44713;function answersUrl(e){return"//api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"//api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

• Does "until cancelled by an interrupt" include closing the program or does it need a mechanism to stop the cycle coded into it? – user81655 Nov 27 '15 at 23:00
• – Mego Nov 28 '15 at 6:21
• Warning: All sleep 1 based answer break rule 5: you must guarantee one, and only one, output of time per second. !! – F. Hauri May 17 '16 at 23:03
• F. Hauri: How so? Rule 6 says "If you wait a second between each output, that is fine as well." – YetiCGN Aug 26 '16 at 22:03
• @Jasen No, but the meaning of "that is fine" implies that the wait option is still valid, regardless of the eventual time loss. I have clarified this for you. – Addison Crump Jan 7 '17 at 19:07

Japt, 8 bytes

Japt is a shortened version of JavaScript.

1e3i@OpÐ


Test it online!

How it works

1e3i@       // Repeat this function every 1e3 milliseconds:
OpÐ    //  Output new Date(), followed by a newline.


Note that this also outputs a seemingly random integer when the code is run. To get rid of this, use this code:

1e3i@OpÐ};P


On my computer, the time is formatted as 2015-11-28T16:00:18.013Z. If you don't like that, try this code instead:

1e3i@OpÐ s8};P


Which will lovingly print your time in the format 11:00:18 AM.

K, 25 24 Bytes

Removed semicolon from the end of the func!

      .z.ts:{-1@$18h$x}
\t 1000
13:11:44
13:11:45
13:11:46
13:11:47
13:11:48
...

.z.ts is called every 1000 milliseconds.
x is the time.
18$x casts the time to the appropriate format.$ - strings the result.
-1@(stringed result) - prints the string to the console.


*Edit Below is less but I wasn't sure whether the time format was allowed;

    .z.ts:{-1($x)} \t 1000 2016.08.01D00:35:37.392683000  C/C++, 219 Bytes Here is a first pass attempt. It is written in C++ but uses only C functionalities, so it could be used as C code with only changes to the include statements (I think). #include<stdio.h> #include<ctime> time_t r;struct tm*x;int main(){char c[9],b[9];time(&r);x=localtime(&r);strftime(c,9,"%T",x);puts(c);for(;;){time(&r);x=localtime(&r);strftime(b,9,"%T",x);if(b[7]!=c[7]){break;} }main();}  I think everything is pretty straightforward. It takes the time at the beginning of the main function, then it continues getting time until one second has passed. It then calls itself. Ungolfed: #include<stdio.h> #include<ctime> time_t r;struct tm*x; int main(){ char c[9];char b[9]; time(&r); x=localtime(&r); strftime(c,9,"%T",x); puts(c); for(;;){ time(&r); x=localtime(&r); strftime(b,9,"%T",x); if(b[7]!=c[7]){break;} // break when the 'second' changes } main(); }  • Erm... I'm not the best with C, but won't this cause a StackOverflow (if I remember right, this might be java seeping in)? – Addison Crump Nov 28 '15 at 1:41 • It doesn't on my computer (using g++) although int main(){main();} does cause a seg fault. – Liam Nov 28 '15 at 1:42 • @VoteToClose I believe that tail recursion gets optimized away. – Maltysen Nov 28 '15 at 1:46 • I get a segfault at about 40000 lines in (removed the waiting system). Don't think it particularly matters at that far in, though. – Addison Crump Nov 28 '15 at 1:50 • With the -O2 switch, gcc/g++ will perform tail call optimization. I'm not sure that's strictly necessary for this answer (since VTC already said it's fine as-is), but it's helpful to know. :) – Mego Nov 28 '15 at 2:09 Vimscript, 44 bytes while 1 echo strftime("%T") sleep 1 endwhile  Run like so: vim -c ":so FILE"  Pyth, 19 16 bytes It takes the relevant part of the datetime list and joins by colons. Then it passes till the second changes, with the entire thang wrapped in an infinite loop. #j\:KP.d2WqeK.d8  While it obviously doesn't work online, you can check its main idea here. • @VoteToClose oh, I actually wrote that a couple mins before you posted. Figured it was okay since it was a catalog. – Maltysen Nov 27 '15 at 23:00 • @FryAmTheEggman That's not necessary, as proven by the Stuck answer and the TI-BASIC answer. It is still human-readable and it is the time. – Addison Crump Dec 1 '15 at 11:00 • Also, you don't need to cut it for just the time string. ;P – Addison Crump Dec 1 '15 at 11:00 PHP, 33 bytes <?for(;;)sleep(print date("r "));  Output is similar to Sat, 28 Nov 2015 11:25:16 +0700, i.e. RFC 2822. • Not sure wether this is allowed. This doesn't output every second for me. This only creates a time value once per second, but doesnt actually show me. – Martijn Nov 30 '15 at 14:24 • Are you invoking from the command line, e.g. php time.php? – primo Nov 30 '15 at 16:36 Mathematica, 41 36 bytes While[1>0,Echo@DateString[];Pause@1]  Works as a script. CJam, 21 bytes L{et6<':*_@={_oNo}|}h  Try it online! Note that the online interpreter will kill the program after one minute. Same idea, but with pretty output: L{et6<3>"%02d:"fe%sW<_@={_oNo}|}h  Try it online! Go, 6469 79 bytes Go isn't very golfy. package main;import(."fmt";."time");func main(){for{Println(Now());Sleep(1e9)}}  You could try it here or on another online interpreter however, for{} is an infinite loop and those are disallowed for obvious reasons. I haven't actually tested thisthere are no go interpreters for my android ): but it should work in theory. Running it locally might cause your CPU fan to speed up, but it won't hog memory. If it crashes with some sort of OOM-error or panic: runtime out of bound, just change it to for x:=0;x<9999;x++{ ... }. • This sleeps for one nanosecond, which results in multiple outputs per second. You'll need Sleep(Second) to fix this. – Michael Hampton Nov 28 '15 at 8:55 • Sleep(1e9) would work, no? I don't remember very much about Go, but I remember something like that. – Addison Crump Nov 28 '15 at 11:05 • @VoteToClose Yes, 1e9 works fine on my cgo 1.5.1... – Michael Hampton Nov 28 '15 at 14:05 • Woo, helped golf a language I've never used! \o/ – Addison Crump Nov 28 '15 at 14:06 • Well yes, that too. I'm using syntastic and vim-go, which has about the same result... – Michael Hampton Nov 28 '15 at 14:12 SpecBAS - 45 bytes Prints in the upper left corner for a continuously updating 24 hour clock. Pressing Esc stops it running. 1 TEXT AT 0,0;TIME$(TIME,"hh:mm:ss"): GO TO 1

• I don't know if this answer would be shorter, but you don't have to necessarily just have the time string. If you output a time string with extraneous data (but still containing the time string), that is fine, so you might have a shorter answer in store. – Addison Crump Nov 28 '15 at 14:46
• TIME on it's own returns a decimal number (days since 30/12/1899!) which then needed formatting to hours/min/secs format. There isn't a function/statement that just returns already formatted date/time string unfortunately. – Brian Nov 28 '15 at 15:04

Processing, 68 bytes

void draw(){frameRate(1);println(hour()+":"+minute()+":"+second());}


Easy one I have to admit. In processing there is the draw() method which is called at a specific frequency that can be modified during the execution.

• Can you show an example output? :D – Addison Crump Nov 28 '15 at 21:40
• A new line every seconds (represented by the spaces) 22:42:32 22:42:33 22:42:34 22:42:35 22:42:36 22:42:37 – 6infinity8 Nov 28 '15 at 21:44
• Oh, so it's not graphical output? – Addison Crump Nov 28 '15 at 21:45
• No, that's printed in the console. I'm just "exploiting" the draw method as a loop. – 6infinity8 Nov 28 '15 at 22:13
• Ohh, I see. Well done, +1 (in about an hour - can't vote right now. :c) – Addison Crump Nov 28 '15 at 22:13

Ruby, 25 24 bytes

Thanks @manatwork for golfing off a byte :P

loop{putsdate;sleep 1}


• print? Either puts or $><< are shorter with identical result. – manatwork Nov 29 '15 at 15:29 • Derp. Thanks for that. (You can tell I don't use Ruby much :P) – a spaghetto Nov 29 '15 at 15:55 Ceylon, 126 112 bytes import ceylon.time{now}void p(){for(e in{now().time().string[0:8]}.cycled.paired){if(e[0]!=e[1]){print(e[1]);}}} This uses the ceylon.time library for getting the current time (in the default timezone) and formatting it (the .string function for time outputs something like 22:33:45.234, so I just take the first 8 characters of it). Unfortunately, there seems to be no sleep function in Ceylon (because it is not easy to implement in JavaScript), therefore I'm doing a busy loop here, comparing each formatted string to the previous one and printing only when there is a change. Here is a formatted version of the second version, which uses a for-loop over an infinite iterable: // print the current time (each second). // // Question: http://codegolf.stackexchange.com/q/65020/2338 // My answer: http://codegolf.stackexchange.com/a/65130/2338 import ceylon.time { now } void p() { for(e in { now().time().string[0:8] }.cycled.paired) { if(e[0]!=e[1]) { print(e[1]); } } }  Using a < instead of != would save a character, but then the program would stop working as soon as the clock hits midnight. This was the original, more functional, version resulting in 112 characters: import ceylon.time { now } void p() { { now().time().string[0:8] } .cycled .paired .map((e) => e[0] != e[1] then e[1]) .coalesced .each(print); }  • Is n=now saving you bytes if you only use it once? I don't know Ceylon, but it seems redundant. – cat Nov 29 '15 at 15:58 • @sysreq actually, no ... for this three-letter identifier it doesn't safe anything (though it also doesn't cost bytes). I'll change this. – Paŭlo Ebermann Nov 29 '15 at 19:02 Hassium, 43 Bytes func main(){print(time())sleep(1000)main()}  See expanded here sh (+ top), 7 bytes Script (Debian8): top -d1  Script (NetBSD7): top -s1  (both without trailing newline) Output (1st line only, Debian8): top - 16:25:15 up 3 days, 8:56, 4 users, load average: 0,97, 1,10, 1,03  Output (1st line only, NetBSD7, different time zone): load averages: 1.46, 1.28, 1.22; (SPACES) up 44+08:52:28 (SPACES) 15:22:06  The amount of spaces depends on the terminal width. C, 74 73 bytes #include<time.h> main(){for(time_t t;!sleep(1);time(&t))puts(ctime(&t));}  The code can work even without #include <stdio.h> and #include <unistd.h>, see live code example on ideone.com -- note: the sleep is zero there, to generate some output before the time limit has been exceeded. The first output line should be ignored ("Extra output doesn't really matter, as long as the program at some point continuously outputs time."). PureBasic, 64 59 bytes Not much to say, infinite loop, output time to the debug window with a 1000 millisecond delay a: Debug FormatDate("%hh:%ii:%ss",Date()) Delay(1e3) Goto a  • ForEver? Seems legit. – Addison Crump Dec 1 '15 at 10:24 • the comment on ForEver made me think about infinite loops and all it boils down to is a Goto loop and it saved me 5 bytes :D – Fozzedout Dec 2 '15 at 11:57 • Goto? Even better. ;D Can you put the a: directly before Debug... to remove the newline? Or is that a different version of BASIC? – Addison Crump Dec 2 '15 at 11:58 • nope, labels for goto's have to be the only statement on the line for it to work. The colon is generally used for stringing multiple commands on one line, so you could have "Debug FormatDate("%hh:%ii:%ss",Date()):Delay(1e3):Goto a" – Fozzedout Dec 3 '15 at 14:42 Prolog (SWI), 72 bytes Formating to user_output stops working when using sleep, so I had to save the time to a variable and print it explicitly. Code: p:-repeat,get_time(T),format_time(atom(X),'%T',T),write(X),sleep(1),1=0.  Explained: p:-repeat, % loop until success get_time(T), % Get current timestamp format_time(atom(X),'%T',T), % Format timestamp as HH:mm:ss write(X), % Print time sleep(1), % Sleep 1 second 1=0. % Fail and go back to repeat  Vitsy + bash, 13 11 bytes This language feature was made after this question, but not for this question. <w1Z,'date' < Loop leftwards in the code. Rest of code is written in reverse for "readability". 'etad' Push 'date' to the stack. , Do the shell script for what's in the stack. Z Output the result. 1w Wait a second.  Or, using eval... <w1Zn"Date()" < Go leftwards through this code in order to loop infinitely. Rest of code is written in reverse for "readability". ")(etaD" Push "Date()" to the stack. n Eval through JS. Z Output everything. 1w Delay for one second.  Try it online! • sleep 1 based answer break rule 5: you must guarantee one, and only one, output of time per second... anymore!! – F. Hauri May 18 '16 at 6:44 • @F.Hauri Please read rule 6 - also, stop spamming me. – Addison Crump May 18 '16 at 6:45 Mouse-2002, 84 bytes Mouse is cool, but it's not the golfiest stack based language on the planet (well, not until I update it in a reimplementation -- then it will be better.) 0&FIX 2&WIDTH "!"(&HOUR &!DEC ":"&MIN &!DEC ":"&SEC &!DEC 8!'8!'8!'8!'8!'8!'8!'8!')$


The 8!' prints the character with ASCII code 8, or backspace. You probably need an ANSI terminal to run this; it updates in place by backspacing over itself and writing the new time once per second.

sample use:

$mouse clock2.mou 19:47:34  Based on this, but golfed. Python 2, 85 bytes import time;while 1:print __import__('datetime').datetime.now().time();time.sleep(1)  import time;time.sleep() has 2 fewer bytes than __import__('time').sleep(), while import datetime;datetime.datetime.now() has 2 more bytes than __import__('datetime').datetime.now(). Emacs Lisp, 83 bytes (run-with-timer 1 1(lambda()(message(format-time-string"%H:%M:%S"(current-time)))))  Groovy, 40 37 bytes Not very golfable :(, thanks to FlagAsSpam for for(;;) :) for(;;){print(new Date());sleep 1000}  • for(;;){...? And what about 1e3 for 1000? You can use print instead of println. – Addison Crump Dec 16 '15 at 14:30 • Thanks, I was pretty sure it needs to be a new line every time. – Fels Dec 16 '15 at 14:36 bash, 35 bytes Just for kicks yes|mapfile -tc1 -C'date;sleep 1 #'  Also 35, x='x[date>&2;sleep 1${!x}]'<${!x}  I think it's unlikely there's anything shorter than exec$0.

• Are you sure the first solution is not als0 35 characters long? I have to put a space in front of the # otherwise sleep cries for invalid syntax. – manatwork Dec 16 '15 at 14:26
• @manatwork Yes. Looks like I tested a version that did ;: before I changed it to # and made a typo. The interactive_comments shopt sometimes screws with me too. Good catch. – ormaaj Dec 16 '15 at 15:11

Python 3, 48 bytes

from time import*
while[sleep(1)]:print(ctime())


It is a @Mego's Python 2 solution tweaked to work on Python 3.
Here's Jupyter notebook to see the results and try it.

Lua, 56 bytes

Lua is pretty hard to golf...

v=1
while 1 do v=os.date'%c' l=v~=l and print(v)or v end


There are few online interpreters that allow infinite loops; one of the few I've found is this one. This repeatedly converts the current system time to a date-time string and outputs that string when it's different from the last.

Ungolfed:

current = 1
while 1 do
current = os.date('%c')
last = current ~= last and print(current) or current
end

• +1 for golfing in lua :). You can golf it down to 51 bytes by using a label+goto to do an infinite loop, and suppress some spaces : v=1::a::v=os.date'%c'l=v~=l and print(v)or v goto a – Katenkyo May 23 '16 at 6:49

Matlab, 50 42 bytes

while 1;pause(1);disp(datestr(now,13));end

• I believe you can use the predefined numeric date format 13 instead of 'HH:MM:SS' and save 8 bytes. – beaker Nov 30 '15 at 17:54
• Somehow I'm noticed this a bit late, but thank you very much! – flawr Jan 24 '16 at 11:18
• Perfect score! :D – beaker Jan 24 '16 at 15:02

Perl 6, 34 30 bytes

Perl 6 is looooong, but I like it. Yes, all the whitespace is needed.

sleep 1 while say DateTime.now


Hooray for postfix syntax!

F#, 101 98 bytes

open System;while 1=1 do(DateTime.Now.ToString"HH:MM:ss"|>printfn"%s";Threading.Thread.Sleep 1000)


Pretty straightforward: print the current time in the correct format, wait a second, then repeat. Forever.

Credit to @VoteToClose and @RikerW for the help.

• Few questions: is for(;;) valid syntax? Can you use DateTime.Now.ToString"HH:MM:ss"? Do you need the whitespace in ; Threading.Thread.Sleep – Addison Crump Feb 2 '16 at 21:42
• Few answers! From what I've seen, for(;;) sadly isn't valid F#. The other two suggestions are dead on, however - I can't believe I've overlooked those. Thanks! =) – Roujo Feb 2 '16 at 21:46
• while (truthy value)? – Rɪᴋᴇʀ Feb 2 '16 at 21:48
• @RikerW Right, that's another good one. I usually write infinite loops as recursive functions, so I hadn't thought about it. Thanks! =) – Roujo Feb 2 '16 at 21:51
• Not just plain 1? – Rɪᴋᴇʀ Feb 2 '16 at 21:58

Rebol, 25 bytes

forever[print now wait 1]


This prints day & time (24 hour HH:MM:SS). For an extra 5 bytes you can make it print just the time: forever[print now/time wait 1]

• Lol, is it said that I read this like house music? Print, now wait 1. Print, now wait 1. – Addison Crump May 20 '16 at 9:35