# 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

/timer 0 1 $time  • Where can we test this? – Addison Crump May 31 '16 at 12:56 • You have to download mIRC it's a shareware IRC client. You can download it from: mirc.com also since the answer above makes use of say you will need to connect to a server and then join a channel. other wise you would use echo instead of say. mIRC has it's own scripting language mSL(mIRC scripting language) – Do0msDay May 31 '16 at 14:01 # tcl, 67 while 1 {puts [clock format [clock seconds] -format %T];after 1000}  # 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  # 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 # 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)


# Dyalog APL, 27 18 16 bytes

':',¨⎕TS⋄→≢⎕DL 1


Try it online!

⎕TS Y M D h m s t
':',¨ prepend : to each
⋄ new statement
⎕DL 1 wait a second and return actual waited time; 1.0something seconds
≢ tally the actual waited time, giving 1
→ go to line (1 = this line)

# 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.

## 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 []
(println (.format (java.text.SimpleDateFormat. "h:m:s a") (java.util.Date.)))))


# Bash, 51312421 20 bytes

Thanks to @quartata for some very helpful comments. Thank you @Dennis for clarifications and for chopping off even more bytes. Thank you @VoteToClose for clarifying the rules (which apparently I am bad at reading) further reducing the bytes.

date displays the the full date with a 24 hour clock. sleep 1 sleeps for a second. exec $0 loops the script infinitely. date;sleep 1;exec$0

• You don't need the shebang. – a spaghetto Nov 28 '15 at 2:52
• Also, I think you can replace the true with the sleep 1 since sleep returns a 1. – a spaghetto Nov 28 '15 at 2:52
• date +%T;sleep 1;exec $0 is a bit shorter. @quartata Nitpicking: sleep has exit code zero, which is why while continues. – Dennis Nov 28 '15 at 3:47 • Oh I'm an idiot – a spaghetto Nov 28 '15 at 3:50 • You don't need the space after date, so this is only 20 bytes. – ThisSuitIsBlackNot Nov 30 '15 at 1:46 ## 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.

# *><>, 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.

# 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

# 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

# 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.

# Elixir, 95 bytes

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


# 05AB1E, 13 bytes

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


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

# 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

# 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.

## 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  # 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 # 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 ## 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  ## 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


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\
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

# 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

# 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

# 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.

# 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.


# 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! – mid Mar 30 '16 at 17:12

# Factor, 43 bytes

[ [ t ] [ now "%c" strftime print ] while ]


An anoymous function. Use it like ~quotation~ call.

## 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