# 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

## Pure bash, 116 113 bytes

Important note: This will print exactly one line by second, even if ( sleep 1 + execution time ) will take more than 1 second!

for((c=1;;c=200-10#${f#*.},c%100>0?s=0,c=c%100:(s=1,c=0))){ read -t$s.$c f;read -a f </p*/up*;printf "%(%c)T\n";}  May ouptput: Tue May 17 21:33:41 2016 Tue May 17 21:33:42 2016 Tue May 17 21:33:43 2016  ## Traced (128 bytes): for((c=1;;c=200-10#${f#*.},c%100>0?s=0,c=c%100:(s=1,c=0))){
read -t $s.$c f;read -a f </p*/up*;printf "%(%c)T%6.2f\n" -1 $s.$c;}


This will output something like:

Tue May 17 21:36:08 2016  0.10
Tue May 17 21:36:09 2016  0.66
Tue May 17 21:36:10 2016  0.99
Tue May 17 21:36:11 2016  1.00
Tue May 17 21:36:12 2016  1.00
Tue May 17 21:36:13 2016  0.99
Tue May 17 21:36:14 2016  1.00
Tue May 17 21:36:15 2016  0.99
Tue May 17 21:36:16 2016  1.00
Tue May 17 21:36:17 2016  0.99
Tue May 17 21:36:18 2016  1.00
Tue May 17 21:36:19 2016  1.00
Tue May 17 21:36:20 2016  0.99


## Square traced (142, for fun!)

for((c=1;;c=200-
10#${f#*.},c%100 >0?s=0,c=c%100:( s=1,c=0))){ rea\ d -t$s.$c f;re\ ad -a f </p*/up* printf "%(%c)T%\ 6.2f\n" -1$s.$c }  ## First, but with some more golfing (119 bytes): for((c=1;;c=200-10#${f#*.},c%100>0?s=0,c=c%100:(s=1,c=0))){
eval read\ -{t\ $s.$c,a\</p*/up*}\ f\;;printf %$$%c$$T\\n;}

• Woah, thems be some complicated bash – Addison Crump May 17 '16 at 20:17
• Yes, but without any external binary! (even no sleep) – F. Hauri May 30 '16 at 22:36

# Batch (Windows), 21 bytes

## t.bat

echo %time%
timeout 1
t


Shows the time, delays for 1 second, then recursively calls itself. This is run as t.bat in the same directory.

• I count 43, but you also need to count the name. If you rename the file to A, then you can bring the score down to 38. – Addison Crump May 31 '16 at 0:42
• Welcome to PPCG! – NoOneIsHere May 31 '16 at 4:09

# MATL, 11 bytes

Z'0XOD1Y.T


### Explanation

         % do...while loop
Z'      %   get current date and time
0XO     %   string representation of date and time, with format 'dd-mmm-yyyy HH:MM:SS'
D       %   convert to string and display
1Y.     %   pause for 1 second
T       %   push "true" value as loop condition to create infinite loop
% implicitly end loop

• Why non competing? – Socratic Phoenix Jul 31 '16 at 16:43
• @SocraticPhoenix Becuase the language is newer than the challenge. I've clarified that in the answer – Luis Mendo Jul 31 '16 at 17:06
• unless I'm mistaken, this is a catalog challenge, meaning you can post languages that are newer... – Socratic Phoenix Jul 31 '16 at 19:27
• Yep, "Since this is a catalog, languages created after this challenge are allowed to compete" – Socratic Phoenix Jul 31 '16 at 19:28
• @SocraticPhoenix Oh, thanks! I hadn't noticed. I'll remove the note then – Luis Mendo Jul 31 '16 at 21:52

## QBasic, 16 bytes

Shamelessly stole (and imporoved upon) Mauris' design:

CLS:?TIME$:RUN  Previous version: 24 bytes EDIT: Only just saw that I don't have to SLEEP 1 if I continuously clear the screen and print the time. That's 4 bytes shorter: DO:CLS:PRINT TIME$:LOOP


Previous entry (28 bytes)

DO:PRINT TIME$:SLEEP 1:LOOP  Nothing fancy, not too shabby. ## TI-BASIC, 29 bytes While 1 Output(1,1,getTimeStr(24)+": Output(1,7,sum(getTime,3 End  TI-BASIC has a built-in getTimeStr, but it doesn't display seconds! How to fix this? Just display the seconds over the empty space after the minutes. (It would be much easier if there were a way to convert numbers to strings.) Outputs in 24-hour mode. • I count 65 bytes there... how do you get 29? – Fozzedout Dec 1 '15 at 10:08 • @Fozzedout TI-BASIC uses a tokenized encoding of one or two bytes per token. – Adám Feb 1 '16 at 19:18 # C#, 129 125 bytes using System;using System.Threading;class P{static void Main(){for(;;){Console.WriteLine(DateTime.Now);Thread.Sleep(1000);}}}  Ungolfed: using System; using System.Threading; class Program { static void Main() { for (;;) { Console.WriteLine(DateTime.Now); Thread.Sleep(1000); } } } • I don't know C# but can't you do for(;;) instead of while(true)? – Blue Nov 30 '15 at 9:45 • Updated, thanks @muddyfish – gamesmad Nov 30 '15 at 10:13 • Can you do 1e3 over 1000? (I don't know C# either.) – Addison Crump Nov 30 '15 at 10:15 • Thread.Sleep accepts either int or TimeSpan. You can do Thread.Sleep((int)1e3) but that's longer unfortunately. – gamesmad Nov 30 '15 at 10:18 # PHP, 24 bytes for(;;)echo date("\rr");  \r clears the current line before printing the date/time using the r flag. Therefor it doesn't have to wait or delay the output for a second. Also the cursor is always positioned behind the output, which would be different for r\r where it would overlay the first character of the output. • "You must output the current time continuously (until cancelled by an interrupt), once every second" ... not every millisecond. – yeti Nov 30 '15 at 15:43 • @yeti See the OP's current last comment on the question: "If it's only one visible output per second, then that should be fine.". – insertusernamehere Nov 30 '15 at 15:46 • Changing the rules in comments is not a good idea... he better should update the original text instead... :-( – yeti Nov 30 '15 at 15:57 • Shouldn't PHP code always include the short open tag or add bytes for using the -r switch? Otherwise, this script will just print the source code. – YetiCGN Aug 26 '16 at 22:13 • @YetiCGN It's accepted throughout this site to not include the PHP opening tag in the byte count. Here's a discussion about it that also links to a few related posts. – insertusernamehere Aug 26 '16 at 22:20 # AppleScript, 11293 45 bytes repeat delay 1 log(do shell script"date") end This repeats in a loop, does the bash script date, gets its returned string, and outputs it to the Messages pane. Why I didn't do this at first, I'll never know. ### Using Node: Let's have a odd useless combination, shall we? This was inspired by my Vitsy answer, which also uses JS to get the date. tell app"System Events" tell app"Terminal"to activate keystroke"node " repeat delay 1 keystroke"Date() " end end What I do here is I tell the System Events application to get terminal as the front window, then enter node with the terminal by telling System Events to simulate keystrokes of n, o, d, e, followed by a newline. It then enters a loop in which it delays for a second, tells node to do Date() by the same method, then going back to the top of the loop. This answer is mostly to demonstrate the odd things that Applescript allows you to do. • sleep 1 based answer break rule 5: you must guarantee one, and only one, output of time per second!! – F. Hauri May 18 '16 at 6:41 • @F.Hauri I've seen you posting this on most things in this question, but read rule 6 carefully as to why this is not always the case. ;) – Addison Crump May 18 '16 at 6:44 # Unix Shell + procps, 12 bytes procps is a package providing CLI utils for browsing procfs, a virtual filesystem generated by the kernel to provide information about processes. The watch command reruns a command every on an interval, that defaults to 2. Set it to 1, and run ., and voilá, watch suppresses stderr. watch -n1 .  The time is in the upper right. incidentally, watch is very handy for spying on the progress of a lengthy dd or cp. # Factor, 43 bytes [ [ t ] [ now "%c" strftime print ] while ]  An anoymous function. Use it like ~quotation~ call. # Pylongolf, 11 bytes >}~.1000w.<  }~ pushes the current time into the stack and then prints it. . the dots reset the stack. 1000w pushes 1000 into the stack and then waits that time. • This not seems to output the time continuously, once per second. – manatwork Mar 30 '16 at 16:48 • Fixed the problem! – user47018 Mar 30 '16 at 17:12 # Jelly, 8 bytes 7ŒTṄœS1ß  Try it online! ### How it works 7ŒTṄœS1ß Main link. No arguments. 7 Yield 7 (or 111 in binary). ŒT Time; return hours, minutes and seconds (lower three bits). Ṅ Print, followed by a linefeed. 1 Yield 1. œS Sleep for 1 second, return the time. ß Call the main link recursively.  # Python, 53 bytes This one prints the date and year as well as the time, so I don't know if it's allowed. import time while 1:print(time.ctime());time.sleep(1)  EDIT: J.F.Sebastian made a shorter one. # Scratch, 15 bytes (scoring used) This script is essentially what it says. It joins the hour value, then a colon, then the minute value, then a colon, then the second value. The downside is that Scratch reads 01 as 1, so it might not be valid without making the script longer. • Hello, and welcome to PPCG! According to Meta, that is 15 bytes, one for each block, and one for each character of text. – NoOneIsHere May 18 '16 at 20:05 • Thanks for pointing that out, I linked the meta post in question for clarity. – weatherman115 May 18 '16 at 22:54 ## Lua, 51 Bytes Since the previous owner of this answer in 56 Bytes doesn't update anymore when suggested improvments, here's a 51 Bytes solution heavily based on his: v=1::a::v=os.date'%c'l=v~=l and print(v)or v goto a  # C#, 102 bytes using System;class P{static void Main(){for(var s="";;)if(s!=(s=DateTime.Now+"\n"))Console.Write(s);}}  An infinite loop that prints whenever the time changes. Default precision for C# date printing is to the second, so that works out nicely. # Tellurium, 8 bytes [i|t^¨]  The code that is after the | and before the ] is run forever (i). It changes the value of the current cell to the current time (t), outputs the current cell's value using ^, and waits for 1 second (¨) before continuing. • "Since this is a catalog, languages created after this challenge are allowed to compete." Hey, what are you waiting for? – user48538 May 20 '16 at 9:41 • @zyabin101 Fixed that! Thanks :) – m654 May 20 '16 at 11:36 # Mathematica, 27 21 bytes With 2 bytes saved thanks to Xavier. Dynamic@{Now,Clock[]}  • 25 bytes with Dynamic@{Now,Clock@{1,2}}, and 21 with: Dynamic@{Now,Clock[]}. – user48818 Aug 27 '16 at 14:59 ## Clojure, 140 bytes (loop[l 0](let[c(System/nanoTime)](recur(if(>=(- c l)1e3)(do(println(.format(java.text.SimpleDateFormat."h:m:s a")(java.util.Date.)))c)l))))  Full program. Loops continually; keeping track of the last time it printed. If 1000ms have passed, it prints, then resets the time. Java interop really bloats this up, but not much can be done about that. Ungolfed: (defn current-time [] (loop [last-ns 0] (let [current-time (System/nanoTime)] (recur (if (>= (- current-time last-ns) 1e3) (do (println (.format (java.text.SimpleDateFormat. "h:m:s a") (java.util.Date.))) current-time) last-ns)))))  ## Using sleep (which seems to be of questionable validity), 100 bytes (while[](Thread/sleep 1e3)(println(.format(java.text.SimpleDateFormat."h:m:s a")(java.util.Date.))))  Ungolfed: (defn current-time [] (while [] (Thread/sleep 1e3) (println (.format (java.text.SimpleDateFormat. "h:m:s a") (java.util.Date.)))))  # Fourier, 46 20 bytes This is a fairly simple program which loops infinitely, using the newly added date functions, delay function and clear screen function. This does not show a leading zero on the minutes or the seconds value when either are less than ten. (@2do58a1do58a0do1;)  Try it online! Note: this program will not work on http://fourier.tryitonline.net due to differences in the way interpreters work. # QBIC, 6 bytes (nc) {_C?_d  QBIC is newer than this challenge. In fact, this challenge is the reason QBIC has a _C command (for CLS - Clear the screen) and the _d/_D commands (for TIME$ and DATE$ resp). ## Explanation { Start infinite loop _C Clear screen ? PRINT _d TIME$ (which holds the system's time in QBasic)


# MOO, 46 bytes

while(!suspend(!player:tell(ctime())))endwhile


Sleeps for one second between outputs, regardless of execution time (and it's impossible to know sub-second timings anyway

# tcl, 67

while 1 {puts [clock format [clock seconds] -format %T];after 1000}


# PHP, 36 34 bytes

a:echo'
'.date(r);sleep(1);goto a;


The line break can be \n but it's nicer to convert the script to the old Macintosh line format and make it \r, then the time is neatly updated on the same line.

1. Removed short open tag as per this meta answer
• for(;;sleep(1))... saves three bytes. echo date("\nr"); is not shorter, but looks cleaner imo. – Titus Jan 7 '17 at 11:42

# 05AB1E, 13 bytes

[žažbžc)':ý,w


Should work, but I don't have Python 3, so I can't test.

# Elixir, 95 bytes

def f, do: 1000|>Stream.interval|>Enum.each(&(&1&&DateTime.utc_now|>DateTime.to_time|>IO.puts))


# Nim, 55 54 bytes

import os,times
while on:echo getClockStr();sleep 1000


on is an alias for true. Prints the result of the times module's getClockStr proc, which formats the time nicely in 24-hour format, then uses the os module's sleep proc to sleep a second.

# *><>, 16 bytes

'::'hnomnosnaoaS


000webhostapp interpreter.

Note: it sometimes skips a second (e.g. 12:34:6 → 12:34:8), because you can't wait exactly a second with total accuracy. Unfortunately there isn't any way to fix this.

# VBA, 50 Bytes

Anonymous VBE immediate window function that takes no input and outputs to the VBE immdiate window

Do:DoEvents:?Now:Application.Wait 1/864E2+Now:Loop