Output the Current Time

48

5

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.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

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

Addison Crump

Posted 2015-11-27T22:55:41.513

Reputation: 10 763

Does "until cancelled by an interrupt" include closing the program or does it need a mechanism to stop the cycle coded into it? – user81655 – 2015-11-27T23:00:13.583

@user81655 Yes, it can be any form of interrupt - don't worry about coding that bit. – Addison Crump – 2015-11-27T23:01:51.090

Is it okay if your language's kernel automatically intercepts interrupts to show a debug menu? – LegionMammal978 – 2015-11-27T23:07:04.223

@LegionMammal978 Absolutely fine. Extra output doesn't really matter, as long as the program at some point continuously outputs time. – Addison Crump – 2015-11-27T23:11:24.220

@VoteToClose Does that mean my answer doesn't actually need the substring call? – SuperJedi224 – 2015-11-27T23:21:11.907

@SuperJedi224 Absolutely correct. – Addison Crump – 2015-11-27T23:24:58.490

Also, if it is in fact allowed to print more than just the current time, you should explicitly say so in the question. – Dennis – 2015-11-28T03:49:14.107

Shall there be a tag [tag:catalog] for "Since this is a catalog, languages created after this challenge are allowed to compete."? – Vi. – 2015-11-28T06:02:53.740

Are we allowed to display something like 01:47:2 for 01:47:02? – lirtosiast – 2015-11-28T06:28:14.617

@ThomasKwa I don't really see a problem with it, as it is human-readable as a time. – Addison Crump – 2015-11-28T11:09:58.947

From my Snap! answer, do I have to keep the wait 1 sec block? It's going to be still like 9:21:8...9:21:9... because unlike most other languages it doesn't keep whatever it said before. – ev3commander – 2015-11-29T14:03:55.587

@ev3commander If it's only one visible output per second, then that should be fine. – Addison Crump – 2015-11-29T18:54:58.203

Looking at your watch: 0 bytes ಠ_ಠ – Arcturus – 2015-12-16T02:41:30.980

May there be spaces between the parts and the colons? 12 : 23 : 34 – Adám – 2016-01-05T21:34:50.773

@NBZ Yes, that's fine. – Addison Crump – 2016-01-05T22:36:11.047

1Warning: All sleep 1 based answer break rule 5: you must guarantee one, and only one, output of time per second. !! – F. Hauri – 2016-05-17T23:03:59.880

1F. Hauri: How so? Rule 6 says "If you wait a second between each output, that is fine as well." – YetiCGN – 2016-08-26T22:03:36.227

@VoteToClose Can I wait a second before the first output? – Erik the Outgolfer – 2017-01-07T09:42:03.580

@EriktheOutgolfer I don't see a reason to disallow it. – Addison Crump – 2017-01-07T10:18:38.440

@YetiCGN in single threaded solutions sleep needs to be tuned to compensate for the time elapsed looping and printing, else one of the printout valies will be skipped sooner or later. therefor breaking "must be one second apart" a "solution" that outpute 1000001 microseconds apart is not compliant so far as I can tell. – Jasen – 2017-01-07T11:28:57.203

@Jasen Please read the sixth rule, which provides an exception to that. – Addison Crump – 2017-01-07T12:22:48.660

rules six does not say "you may ignore the description and rule five and do this instead" it only says must... – Jasen – 2017-01-07T19:01:45.507

1@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 – 2017-01-07T19:07:32.213

the time of the first incorrect output is random therefore, program only has to output once! ??? – Jasen – 2017-01-07T19:12:19.103

Answers

55

Minecraft 1.8.7, 7 + 8 = 15 blytes (bytes + blocks)

Only one command block involved:

xp 1 @p

Output goes to the client console like so:

times

As part of the normal output.

This is the system:

the system

xp gives a specified amount of experience to a specified player with the syntax xp <amount> <player>. I'm pretty sure this is the smallest command that has singular output that I can get, now.

Addison Crump

Posted 2015-11-27T22:55:41.513

Reputation: 10 763

Doesn't this solution also depend on the existence of the repeaters and their timings? That would add more bytes. – LegionMammal978 – 2015-11-27T23:13:39.070

@LegionMammal978 I accounted for that - 12 (bytes of code) + 8 (blocks used). – Addison Crump – 2015-11-27T23:25:50.730

3Don't say "19 bytes" because you didn't measure your answer size in bytes. – feersum – 2015-11-28T00:00:53.490

6

@feersum There's a reason for me saying bytes, trust me. This is the closest thing to a consensus for MC as of now.

– Addison Crump – 2015-11-28T00:04:26.510

4You can use the deprecated number codes can't you? – Conor O'Brien – 2015-11-28T02:07:08.850

4Use this scoring system if you want, 19 whatevers, but it isn't 19 bytes, because there is no previously defined encoding that allows you to store this solution in a 19-byte file. – feersum – 2015-11-28T05:47:57.430

1@CᴏɴᴏʀO'Bʀɪᴇɴ I'd have to wrap it in JSON, I believe. Unless I used 1.6, but that's practically another language. – Addison Crump – 2015-11-28T11:00:41.300

@VoteToClose Does an error message show up on both sides? (Also, for reference, the GZIP'ped schematic is 211 bytes long.) – LegionMammal978 – 2015-11-28T12:23:31.410

@LegionMammal978 What do you mean by error message? (I'm using the consensus byte count. :P Although I am interested in how you get the schematic...?) – Addison Crump – 2015-11-28T12:47:17.257

@VoteToClose It should produce an error message when given an invalid command such as a, and I was wondering if this showed up on both the server and client. I can't use MC right now, so I was wondering if you could test it. I hand-wrote the 256-byte schematic, then used gzip -n9 on it. The new tp version is 206 bytes long. – LegionMammal978 – 2015-11-28T13:15:19.547

@LegionMammal978 Error does not go to client console. Also, I just found a shorter way with xp 1 @p. – Addison Crump – 2015-11-28T13:22:50.297

@VoteToClose If the error doesn't go to the client, then you can use its timestamp! – LegionMammal978 – 2015-11-28T13:23:42.607

@LegionMammal978 The error is only put out to the command block timestamp, which is only accessible by clicking it. Don't think it really counts as continuous output. – Addison Crump – 2015-11-28T13:27:12.080

Let us continue this discussion in chat.

– LegionMammal978 – 2015-11-28T13:28:41.820

Or, to give you much more experience, do xp 9 @p. – ev3commander – 2015-11-29T21:28:07.030

@ev3commander Eh. Who needs xp, anyways? – Addison Crump – 2015-11-29T22:00:23.853

Couldn't you use say a? I am 99% sure that only puts one thing in the log. (It says a in the chat). – Pokechu22 – 2015-11-30T17:33:52.107

@Pokechu22 It puts a command output AND a chat output, so no – Addison Crump – 2015-11-30T18:23:51.750

is that the smallest redstone creation you can make – ev3commander – 2015-12-09T21:27:11.993

@ev3commander Couldn't find another way to delay a second. :P – Addison Crump – 2015-12-09T22:33:29.623

Use 1.9/1.10 repeating and chain command blocks. You can golf furthur than this with them . – None – 2016-07-15T15:22:02.277

@GLASSIC I don't think I can - I need that second delay, and to use a repeating command block querying for a second of change in daytime would take more bytes than it's worth. – Addison Crump – 2016-07-15T18:03:31.627

Why not 6 block timer? Why not me .? – l4m2 – 2018-10-27T06:09:13.937

17

JavaScript, 32 bytes

setInterval("alert(Date())",1e3)

Uses the fact that setInterval evaluates code. This is not recommended, but when was that a concern in code golf?

Date() returns the current time and date in a format like this (may vary per system).

 Wed Jul 28 1993 14:39:07 GMT-0600 (PDT)

intrepidcoder

Posted 2015-11-27T22:55:41.513

Reputation: 2 575

Would setInterval(alert,1e3,Date()) work instead? – ETHproductions – 2015-12-09T18:24:36.020

@ETHproductions It always shows the same time for me – ev3commander – 2015-12-09T21:28:33.417

@ETHproductions in your example Date() will only be evaluated once when you create the interval – MMM – 2015-12-14T13:00:59.170

15

Snap, 8 7 6 blocks


(Yes, I changed it in MS Paint because I was too lazy to make another screenshot. So what? At least it's readable.)
click the script to run
24-hour clock.

ev3commander

Posted 2015-11-27T22:55:41.513

Reputation: 1 187

2I always love graphical programming languages. :D +1 – Addison Crump – 2015-11-28T14:27:35.793

oh hey ev3! I know you from Snap/Scratch forums :P why do you need Snap instead of Scratch, exactly? – anOKsquirrel – 2015-11-28T14:43:31.697

2@anOKsquirrel Because I don't need to nest all those join blocks. – ev3commander – 2015-11-28T14:45:08.660

Shouldn't that read 9:21:08? – Luke – 2015-11-30T14:06:58.393

@Luke As shown by the TI-BASIC answer, the time without the leading zero in an output is fine. It is human readable and clear what the time is. – Addison Crump – 2015-11-30T19:48:47.110

That image gives me a 404. It would be preferable to upload essential images to SE's imgur account, which should never be deleted. – Dennis – 2015-12-16T19:12:11.743

It works fine for me. – ev3commander – 2015-12-16T20:08:42.760

Using 'MS Paint' should disqualify anyone at anytime. – CousinCocaine – 2016-01-24T21:36:38.647

Oh, ok, so scratch counts as a programming language as well? – ghosts_in_the_code – 2016-02-01T17:54:13.140

15

sh (+ watch), 11 bytes

Script:

watch -n1 .

(no trailing newline)

Output:

Every 1,0s: . (SPACES) Sat Nov 28 19:07:51 2015

The amount of spaces depends on the terminal width.

Tested on Debian8 and NetBSD7.

user19214

Posted 2015-11-27T22:55:41.513

Reputation:

Right tool for the job, +1 – Addison Crump – 2015-11-28T18:13:31.233

Wait, does this count as a programming language? Can you give me a link to an interpreter? – Addison Crump – 2015-11-28T18:34:49.237

@VoteToClose watch is a coreutil. The real language is bash/sh. – Doorknob – 2015-11-28T18:35:48.453

So... shouldn't this be Bash (distribution), not watch? @Doorknob – Addison Crump – 2015-11-28T18:37:05.983

According to apt-file watch is in package procps. I'll change the language to sh. – None – 2015-11-28T18:38:10.370

1Hmm You have to use -p switch to not break the rule you must guarantee one, and only one, output of time per second.!! – F. Hauri – 2016-05-17T23:00:43.333

watch is a coreutil, but only code written is -pn1 . – Jasen – 2017-01-07T11:34:31.830

11

Python 2, 47 bytes

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

No online link because ideone times out (huehuehue) before printing anything.

Thanks to @xsot for the while[sleep(1)] trick and the ctime trick.

Prints out the current date and time like so: Fri Nov 27 21:23:02 2015

Mego

Posted 2015-11-27T22:55:41.513

Reputation: 32 998

2/me claps slowly at the pun. Very funny Mego. ;D – Addison Crump – 2015-11-28T00:15:16.343

I've posted your solution for Python 3

– jfs – 2015-11-30T19:45:34.627

sleep 1 based answer break rule 5: you must guarantee one, and only one, output of time per second. – F. Hauri – 2016-05-17T23:01:30.510

@F.Hauri sleep 1 causes the current thread to sleep for exactly one second. It complies with the rules. – Mego – 2016-05-18T00:35:39.297

@Mego No: If you sleep exactly 1 second between each operation of printing system time, If printing time take only 1 µs, You will miss 1 output every million of sec. – F. Hauri – 2016-05-18T06:12:18.240

@F.Hauri It's more likely that something else beyond the program's control (like exhaustion of resources, a crash/reboot, cosmic rays, etc.) will happen that disrupts the program's execution in the 11.5 days of continuous running that it would take for a 1-microsecond delay for printing to build up to missing a second. – Mego – 2016-05-18T06:17:26.033

Printing time could take a lot more than just 1µs! Anyway you're wrong: sleep 1 break rule 5. – F. Hauri – 2016-05-18T06:36:05.433

1

@F.Hauri Considering that the challenge author himself uses the equivalent of sleep(1) in both his AppleScript solution and his Vitsy+bash solution, it's clearly acceptable.

– Mego – 2016-05-18T06:38:49.757

I disagree. if it was acceptable he would have said approximately. – Jasen – 2017-01-07T11:36:26.603

9

Javascript ES6, 43 39 bytes

setInterval(_=>console.log(Date()),1e3)

Works with my current time settings (which have not been changed for some time, thank you), at least.

4 bytes saved by Conor O'Brien.

SuperJedi224

Posted 2015-11-27T22:55:41.513

Reputation: 11 342

alert is shorter? – Maltysen – 2015-11-27T23:09:58.670

8@Maltysen I think in many browsers you have to close one alert window in order to see the next one. – flawr – 2015-11-27T23:10:54.610

@Maltysen I tried it, messes up the interval somehow – SuperJedi224 – 2015-11-27T23:11:44.970

1You don't need .toTimeString() in Chrome and FF. – Bob – 2015-11-30T06:45:57.787

1I think you can replace new Date() with Date() – Conor O'Brien – 2015-12-13T22:39:48.950

9

Perl, Command Line, 24 bytes

sleep(say)while$_=gmtime

This must be run from the command line, as perl -E'sleep(say)while$_=gmtime' (on windows, use double quotes instead). The date will be output along with the time, which seems to be allowed.


Perl, 25 bytes

sleep print$/.gmtime;do$0

In a scalar context, gmtime will return a string similar to Sat Nov 28 10:23:05 2015. The result from print, always 1, is used as the parameter for sleep. do$0 is used to execute the script again, after the timer has finished.

primo

Posted 2015-11-27T22:55:41.513

Reputation: 30 891

2

As evidenced by @VoteToClose's AppleScript solution and comment, you do not need to extract the time.

– Mego – 2015-11-28T03:36:55.650

1Another 24-byte solution: {sleep say~~gmtime;redo}. – Denis Ibaev – 2016-05-17T20:14:21.943

sleep 1 based answer break rule 5: you must guarantee one, and only one, output of time per second. – F. Hauri – 2016-05-17T23:05:11.013

@F.Hauri the rule was added after this post was made. – primo – 2016-05-18T00:29:56.260

8

Arcyóu, 27 bytes

(@ t(pn(zz 1)(p(st %H:%M:%S

I had to kludge together two new functions for this challenge, zz and st.

pn: Exactly like Lisp's progn.

zz: Direct link to Python's time.sleep.

st: Direct link to Python's time.strftime.

Normally, quotes would be necessary around the format string, but since there are no spaces, it's parsed as a symbol. The interpreter evaluates undefined symbols as themselves, so we get a string.

jqblz

Posted 2015-11-27T22:55:41.513

Reputation: 2 062

1I would up vote, but I don't have any votes left. +1 ;c And nice updates. :D – Addison Crump – 2015-11-28T20:54:25.373

7

Bash, 51 31 24 21 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

Liam

Posted 2015-11-27T22:55:41.513

Reputation: 3 035

You don't need the shebang. – a spaghetto – 2015-11-28T02:52:12.787

Also, I think you can replace the true with the sleep 1 since sleep returns a 1. – a spaghetto – 2015-11-28T02:52:44.723

date +%T;sleep 1;exec $0 is a bit shorter. @quartata Nitpicking: sleep has exit code zero, which is why while continues. – Dennis – 2015-11-28T03:47:35.813

3Oh I'm an idiot – a spaghetto – 2015-11-28T03:50:38.873

You don't need to cut the string down, it can have extraneous output. c: Your code now becomes date;sleep 1;exec $0. – Addison Crump – 2015-11-28T14:36:15.680

2You don't need the space after date, so this is only 20 bytes. – ThisSuitIsBlackNot – 2015-11-30T01:46:53.350

some seconds wil be missed if you wait long enough. – Jasen – 2017-01-07T11:08:17.670

6

Befunge 98, 53 bytes

 v
v>"EMIT"4(>H.8,':,M.8,':,S:.8,d,
>:S-    !!k^

Notes:

  1. This program does not zero-pad the numbers it prints.
  2. This program prints a space and then a backspace character after every number, as the . command prints an implicit space at the end.
  3. The size of the stack in this program grows every second, and thus it will eventually run out of memory.
  4. This program will overwrite the previous time when it prints a new one. To make it print each time on a new line, change the d on the first line to an a

pppery

Posted 2015-11-27T22:55:41.513

Reputation: 3 987

Why is the "TIME" string necessary? Is there some way it's grabbing it? (I didn't know about this) – Addison Crump – 2015-11-27T23:38:31.203

The "EMIT"4( at the beginning of the program is telling the interpreter to load the TIME fingerprint, which enables the H,M, and S instructions. (No, it doesn't emit the number 4). – pppery – 2015-11-27T23:39:57.160

That is awesome. I never even thought that many esolangs would do this, +1. – Addison Crump – 2015-11-27T23:41:22.293

@VoteToClose Befunge 98 even has an instruction to execute an arbritrary program popped from the stack. – pppery – 2015-11-27T23:42:19.067

1runs off to learn this language Excuse me... – Addison Crump – 2015-11-27T23:42:53.643

6

mIRC 7.49 20 16 Bytes

/timer 0 1 $time

O S

Posted 2015-11-27T22:55:41.513

Reputation: 221

Where can we test this? – Addison Crump – 2016-05-31T12:56:12.547

You have to download mIRC it's a shareware IRC client. You can download it from: http://www.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)

– O S – 2016-05-31T14:01:47.920

5

Jolf, 14 8 7 bytes

Crossed out 14 is a striked 1? Naw, it will never catch on ;)

Try it here! Click run, do not click on anything else ^_^ the page is highly... explosive. Yes. Fixed output system with update.

TaD#`~2

(I added some constants, and ~1 to ~4 are powers of 10.)

Explanation

setInterval("alert(Date())",1000);
     T         a      D#   ` ~2

Conor O'Brien

Posted 2015-11-27T22:55:41.513

Reputation: 36 228

4Someone should create YAJSGV (Yet Another JavaScript Golfing Variant). – intrepidcoder – 2015-11-28T03:43:46.520

This seems to print a lot more than just the time. – Dennis – 2015-11-28T03:45:37.217

1

@Dennis I assumed that was fine as per other solutions

– Conor O'Brien – 2015-11-28T03:48:08.703

My bad, I had only read yours and the Bash answer. – Dennis – 2015-11-28T03:48:41.350

@Dennis Not a problem ^_^ – Conor O'Brien – 2015-11-28T03:48:56.867

Doesn't print once per second. – Neil Smithline – 2015-11-28T06:29:46.303

@CᴏɴᴏʀO'Bʀɪᴇɴ This doesn't guarantee output once per second, as neglecting to click the 'okay' button doesn't let it continue. – Addison Crump – 2015-11-28T11:03:59.167

@VoteToClose okay; simple fix by changing to console logging. Will do once not on mobile – Conor O'Brien – 2015-11-28T15:33:56.797

@intrepidcoder So far there are at least 3 – ev3commander – 2015-11-28T15:58:36.957

@NeilSmithline See revisions. – Conor O'Brien – 2015-11-29T17:12:02.170

@BlockCoder1392 There is function golf.

– user48538 – 2016-01-05T19:28:21.417

5

AutoHotkey, 50 bytes

x::Send,% a!=A_Sec? A_Hour ":" A_Min ":" a:=A_Sec:

Notes:

  1. Requires you to hold x for continuous output.
  2. Remove your finger from x to interrupt and end the output.
  3. Output is in 24-hour format.

errorseven

Posted 2015-11-27T22:55:41.513

Reputation: 220

2You could, for a few extra bytes, put that in a tooltip so it doesn't require the user to hold x. – Michelfrancis Bustillos – 2016-05-18T11:58:06.913

5

C (on Linux x64), 179 177 175 168 159 bytes

#include<time.h>
#include<sys/time.h>
main(){struct timeval a;char b[9];for(;;){gettimeofday(&a,0);strftime(b,9,"%T",localtime(&a.tv_sec));puts(b);sleep(1);}}

Ungolfed:

#include <time.h>
#include <sys/time.h>
main(){
  struct timeval a;
  char b[9];
  for(;;){
    gettimeofday(&a, 0);
    strftime(b, 9, "%T",localtime(&a.tv_sec));
    puts(b);
    sleep(1);
  }
}

Only tested on, and likely only functions on, linux x64 (x32 might work, but other platforms probably won't).

The main difference between this program and the other posted C program is the use of linux-exclusive function calls, which, while terrible practice for real software, saves quite a few bytes...if you ignore all the compiler warnings.

Gamerdog

Posted 2015-11-27T22:55:41.513

Reputation: 51

Welcome to PPCG! Unless I'm mistaken, I believe you can remove the space between #include and <...>. Also, can you use 1e6 instead of 1000000? – Addison Crump – 2015-11-28T14:33:30.127

@VoteToClose You were right about the spaces in the #includes. It doesn't look like usleep() accepts 1e6, though - based on how fast it starts spitting out timestamps it just interprets it as 1. – Gamerdog – 2015-11-28T14:37:49.940

¯\(ツ)/¯ I don't really know C, either. I'll let the professionals at that. Welcome again, have an up vote. :D – Addison Crump – 2015-11-28T14:39:29.373

Ah, another thing - you don't have to cut the string for just the time, so you can just output the entire date time, provided it has the time string required in it. – Addison Crump – 2015-11-28T14:42:27.520

@VoteToClose It's actually shorter not to. The gettimeofday() syscall doesn't actually return the time of day - as far as I can tell it returns the length of time since the epoch (1/1/1970). strftime() turns that into a readable timestamp based on the system time. This is the shortest I can think to get it while only using C and syscalls. – Gamerdog – 2015-11-28T14:50:21.263

Huh. Well done, then, +1. – Addison Crump – 2015-11-28T15:07:06.273

I guess you can replace the NULL BY 0, saving 3 more. Try that out! – Sahil Arora – 2015-11-29T01:54:35.787

2You can use %T as the format spec in strftime. – Mego – 2015-11-29T02:41:46.237

5

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)

Adám

Posted 2015-11-27T22:55:41.513

Reputation: 37 779

4

PHP, 37 bytes

<?=date('G:i:s');header('refresh:1');

Outputs the formatted server time and sets the page to refresh every second.

Of course, it depends on your internet connection and how fast-repsonding your server is :)

Demo

nicael

Posted 2015-11-27T22:55:41.513

Reputation: 4 585

Nope, no refreshing : Warning: Cannot modify header information - headers already sent – Martijn – 2015-11-30T14:20:20.490

@Martijn I have no idea what you can mess with, because it works for me :) – nicael – 2015-11-30T14:40:38.780

I'll remove the downvote as benefit of the doubt, but this works exactly once for me. Tried on two different regular servers. – Martijn – 2015-11-30T14:42:12.147

2Depends on whether you have output buffering turned on. – Andrea – 2016-07-11T00:10:09.190

<?=header('refresh:1').date('G:i:s'); should work with either output bffering setting. – Jasen – 2017-01-07T11:17:55.617

4

Powershell, 19 bytes

for(){date;sleep 1}

Danko Durbić

Posted 2015-11-27T22:55:41.513

Reputation: 10 241

As it's since been pointed out that output merely needs to include the hh:mm:ss you can reduce to for(){date;sleep 1} – steve – 2015-11-28T23:25:50.963

4

Perl 6, 29 bytes

The right way to do this:

Supply.interval(1).tap: -> $ {
  say join ':',.hour,.minute,.whole-second given DateTime.now
}
await Promise.new; # halt this thread indefinitely
22:21:58
22:21:59
22:22:0
22:22:1
22:22:2
…

The golfed version

loop {sleep say join ':',now.polymod(1,60,60,24)[3…1]} # 56 bytes
3:59:26
3:59:27
3:59:28
3:59:29
…

Since the output doesn't have to be restricted to just the time, I can make it quite a bit shorter.

loop {sleep say DateTime.now} # 29 bytes
2015-11-27T22:18:10-06:00
2015-11-27T22:18:11-06:00
2015-11-27T22:18:12-06:00
2015-11-27T22:18:13-06:00
…

Brad Gilbert b2gills

Posted 2015-11-27T22:55:41.513

Reputation: 12 713

4

R, 38 bytes

repeat{Sys.sleep(1);print(Sys.time())}

This outputs the current time in the following format:

[1] "2015-11-28 07:34:01 CET"

Sven Hohenstein

Posted 2015-11-27T22:55:41.513

Reputation: 2 464

4

VBA, 69 Bytes

Getting the Time is easy, now() Only outputting every 1 second.... MUCH more verbose.

This is the "Right" way of waiting 1 second in VBA. 78 Bytes

Sub a():Debug.Print Now():Application.Wait Now()+TimeValue("0:0:1"):a:End Sub

Or if you want to Cut some Corners and only being right 86% of the time is good enough 63 Bytes
adding one SigFig take you to 95% accurate and a third will get you to 99.36%

Sub a():Debug.Print Now():Application.Wait Now()+1e-5:a:End Sub

If you want to get the above method to 100% then you need 69 Bytes (1/86400)

Sub a():Debug.Print Now():Application.Wait Now()+(1/86400):a:End Sub

All of these methods would stumble on a leap second Beacuse they do not wait for 1 second, But wait untill 1 second. At midnight when the clocks fall back an hour this clock will stop for 1 hour and then pick up where it left off.

VBA does allow for the Sleep Method but your byte couter is Ruined. 97 Bytes

Declare Sub Sleep Lib "kernel32" (ByVal k as Long)
Sub a():Debug.Print Now():Sleep(1e3):a:End Sub

JimmyJazzx

Posted 2015-11-27T22:55:41.513

Reputation: 691

3

AppleScript, 51 35 bytes

repeat
log current date
delay 1
end

Pretty dang obvious. Prints the current date, which contains the time, delays a second, then continues.

Addison Crump

Posted 2015-11-27T22:55:41.513

Reputation: 10 763

1So wait, is it allowed to print out the current date as well as the time? – a spaghetto – 2015-11-28T03:31:01.583

@quartata Yes, any concatenation with the time, as long as the time is continuously output and guaranteed to be output, is fine. – Addison Crump – 2015-11-28T10:59:53.333

delay 1 does what? pause for 1000000000 ns? – Jasen – 2017-01-07T11:19:40.540

@Jasen That's correct. – Addison Crump – 2017-01-07T12:22:07.830

3

Perl, 99 81 75 51 40 36 29 27 bytes

sleep(print gmtime.$/);do$0

steve

Posted 2015-11-27T22:55:41.513

Reputation: 2 276

1You can shorten it by using gmtime instead of localtime. – Brad Gilbert b2gills – 2015-11-28T03:11:41.717

2Also printf"%02d:%02d:%02d\n",(gmtime)[2,1,0] – Brad Gilbert b2gills – 2015-11-28T03:18:33.553

1gmtime."\n" will force a scalar context. – primo – 2015-11-28T15:12:30.767

1You should almost never need to do ."\n" in golf: use .$/ to save 2 bytes. At the very least, use a literal newline instead of \n to save 1 byte. – ThisSuitIsBlackNot – 2015-12-01T19:40:55.460

3

JavaScript, 47 38 35 bytes

for(p=1;t=Date();p=t)t!=p&&alert(t)

Explanation

Continuously checks if the time has changed then alerts if it has.

for(
  p=1;
  t=Date();
  p=t
)
  t!=p
    &&alert(t)

user81655

Posted 2015-11-27T22:55:41.513

Reputation: 10 181

You don't have to just get the time string. ;D As long as it's in there somewhere. – Addison Crump – 2015-11-28T00:49:52.673

@VoteToClose Oh true! – user81655 – 2015-11-28T00:54:29.283

Don't think you need the +"", as without new, Date() returns a string. – ETHproductions – 2015-11-28T01:25:54.867

@ETHproductions Ah, yes that was left there from when it used new. Thanks for catching that! – user81655 – 2015-11-28T01:29:14.233

3

Java, 300 166 137 125 124 bytes

Nearly More than halved thanks to VoteToClose, Paülo Ebermann and janschweizer!

interface A{static void main(String[]a)throws Exception{for(;;Thread.sleep(1000))System.out.println(new java.util.Date());}}

Ungolfed:

interface A {
    static void main(String[] a) throws Exception {
        for (;; Thread.sleep(1000)) System.out.println(new java.util.Date());
    }
}

cat

Posted 2015-11-27T22:55:41.513

Reputation: 4 989

@VoteToClose Now it is Java. – cat – 2015-11-28T14:48:07.223

1Simplify your imports: java.util.* instead of the two java.util imports, java.text.* for the same reasoning. Use for(;;) for infinite loops. Use String[]a in the main declaration. Use interface A{static void main(..., as this will shorten it even more. You can use Exception over InterruptedException, and you can replace ex with e. You can also remove all text inside the catch, as this does nothing anyways. – Addison Crump – 2015-11-28T14:51:16.193

You will need Java 8 for the interface trick. ;) – Addison Crump – 2015-11-28T14:53:10.433

@VoteToClose Thank you so much! I just did a tiny bit of googling and got this to compile so I'll add those! I do have Java8 :) – cat – 2015-11-28T14:54:49.903

1Yeah, the interface thing is a little wacky - I have no idea why Java would let that be a thing, considering that interfaces are specifically designed to be unrunnable. – Addison Crump – 2015-11-28T14:56:47.977

1Two things: you need to change the time string to "HH:mm:ss" - as of now, you're formatting "Hour:Month:Second". Also, since you're using a loop, you can get rid of the DateFormat and Calendar variables declarations all together. You replace the contents of the for loop with System.out.println(new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()));try{Thread.sleep(1000);}catch(Exception e){}. – Addison Crump – 2015-11-28T15:40:10.030

1All of the things I just suggested, wrapped up: import java.util.*;import java.text.*;interface A{static void main(String[]a){for(;;){System.out.println(new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()));try{Thread.sleep(1000);}catch(Exception e){}}}} – Addison Crump – 2015-11-28T15:42:39.863

I think you don't need the calendar, you can directly use new Date() for the current time. – Paŭlo Ebermann – 2015-11-28T19:00:57.837

@PaŭloEbermann Fixed, thanks! – cat – 2015-11-29T04:52:26.530

1throws Exception is shorter than a try/catch – phase – 2015-11-29T07:21:16.833

1Also, your import of java.text is not needed anymore. – Paŭlo Ebermann – 2015-11-29T10:31:48.233

1Some more bytes to golf: 1. Save 3: Move Thread.sleep(1000) into for-loop - killing off two brackets { } and one semikolon ; 2. kill the import of java.util and write new java.util.Date() instead - saving another 9: interface S{static void main(String[] a)throws Exception{for(;;Thread.sleep(1000))System.out.println(new java.util.Date());}} – janschweizer – 2015-11-30T09:34:16.707

@janschweizer ???

– cat – 2015-11-30T18:45:35.897

Because of the brackets [], you can save a byte by removing the space in the parameter of main, i.e. main(String[]a). – rgettman – 2015-11-30T21:06:47.847

@rgettman duh, I knew that but I didn't see it, thanks – cat – 2015-11-30T22:19:45.987

3

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.

ETHproductions

Posted 2015-11-27T22:55:41.513

Reputation: 47 880

3

Haskell, 98 96 85 bytes

import GHC.Conc
import Data.Time
m@main=getCurrentTime>>=print>>threadDelay(10^6)>>m

Alternate version using do notation:

main = do
  time <- getCurrentTime
  print time
  threadDelay 1000000
  main

Gets the current time with getCurrentTime from the Data.Time library, then pipes it into print, waits 1,000,000 microseconds (1 second) and calls itself.

Thanks to nimi and Mauris!

Craig Roy

Posted 2015-11-27T22:55:41.513

Reputation: 790

m@main=...>>m is always shorter than main=...>>main – Lynn – 2015-11-29T15:59:14.883

Also, since threadDelay is GHC-specific anyway, you could import it from GHC.Conc

– Lynn – 2015-11-29T16:01:52.640

3

Batch - 34 40 bytes

I love built-in variables:

:A                    //Set label A
echo %time%           //Print the time in 24 hour format
timeout 1    //Wait 1 second (thanks DavidPostill)
goto A                //Jump back to A and repeat

There definitely needs to be some sleep command in Batch anytime soon.

GiantTree

Posted 2015-11-27T22:55:41.513

Reputation: 885

No builtin sleep but there is timeout. You can replace the ping ... with timeout 1. Also the clock isn't very accurate when using ping. It's better with timeout ;)

– DavidPostill – 2015-11-29T20:36:54.420

@DavidPostill thanks for the tip, I never knew there was such a command in Windows. :) – GiantTree – 2015-11-29T20:39:41.303

@GiantTree You're very welcome ;) – DavidPostill – 2015-11-29T20:40:25.317

Golf: remove :A and replace goto A with %0 – stevefestl – 2017-05-20T15:15:02.210

3

, 13 chars / 25 bytes

Ĥ⇀ôᶁ⬮+⬬),1)

Try it here(Firefox only).

This is surprisingly readable.

Mama Fun Roll

Posted 2015-11-27T22:55:41.513

Reputation: 7 234

4When you say "surprisingly readable", you know you're dealing with an amusing language. +1 – Addison Crump – 2015-11-29T00:47:55.703

3

Dyalog APL, 36 bytes

Not very short this time.

{⎕←1↓∊'⊂:⊃,ZI2'⎕FMT 3↑3↓⎕TS⋄∇⎕DL 1}1

This outputs 24-hour time, i.e.:

14:37:44
14:37:45
14:37:46
...

Explanation:

  • {...}1: define a function and call it (the argument is ignored, but we need the function in order to call it recursively)
    • ⎕TS: a system function that returns the current date and time, in the format year - month - day - hour - minute - second - millisecond. (⎕TS = timestamp)
    • 3↑3↓: drop the first 3 items (i.e. year - month - day) and then take the first 3 items that are left (hour - minute - second).
    • '⊂:⊃,ZI2'⎕FMT: format each number as a two-digit integer (I2) with leading zeroes (Z), prefixed by a colon (⊂:⊃). (This results in a matrix.)
    • : Get all the elements in the matrix, in row order. (This gives a vector, in this case a string.)
    • 1↓: drop the first character (which is an extra :)
    • ⎕←: output it
    • ⎕DL 1: then wait one second (⎕DL = delay)
    • : call the function recursively

marinus

Posted 2015-11-27T22:55:41.513

Reputation: 30 224

{⎕←1↓∊':',¨⍕¨3↑3↓⎕TS⋄∇⎕DL 1}1 for 28 bytes, is enough as per OP. – Adám – 2015-12-10T01:25:40.913

The new rules allow garbage output and random spaces, so you can get rid of a lot. – Adám – 2016-01-05T22:51:55.017

3

QBasic, 18 bytes

?TIME$
SLEEP 1
RUN

Lynn

Posted 2015-11-27T22:55:41.513

Reputation: 55 648

3

Python 3, 99 Bytes

Apologies if it formats the code weird, doing this from an ipad. (dont ask). I know this code is big considering some of the other answers, but I didn't see a python one yet so I wanted to add it in.

import time
import datetime
while(True):
 print(datetime.datetime.now().time())
 time.sleep(1)  

Ashwin Gupta

Posted 2015-11-27T22:55:41.513

Reputation: 471

You can replace True with 1, and if you put the print and sleep lines on the same line as the while (separated with a semicolon) it saves you the whitespace. – undergroundmonorail – 2015-12-09T13:40:47.637

@undergroundmonorail ok thanks for the True/1 tip. I'm not used to that since Java Dosent do that. I didn't know that Python had semicolons either. I'll look into that – Ashwin Gupta – 2015-12-09T15:02:26.747

3

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

Chromozorz

Posted 2015-11-27T22:55:41.513

Reputation: 338

2

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.

Maltysen

Posted 2015-11-27T22:55:41.513

Reputation: 25 023

@VoteToClose oh, I actually wrote that a couple mins before you posted. Figured it was okay since it was a catalog. – Maltysen – 2015-11-27T23:00:27.630

@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 – 2015-12-01T11:00:11.107

Also, you don't need to cut it for just the time string. ;P – Addison Crump – 2015-12-01T11:00:34.297

2

Mathematica, 41 36 bytes

While[1>0,Echo@DateString[];Pause@1]

Works as a script.

LegionMammal978

Posted 2015-11-27T22:55:41.513

Reputation: 15 731

2

Matlab, 50 42 bytes

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

flawr

Posted 2015-11-27T22:55:41.513

Reputation: 40 560

1I believe you can use the predefined numeric date format 13 instead of 'HH:MM:SS' and save 8 bytes. – beaker – 2015-11-30T17:54:31.280

Somehow I'm noticed this a bit late, but thank you very much! – flawr – 2016-01-24T11:18:11.583

2Perfect score! :D – beaker – 2016-01-24T15:02:32.387

2

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();
}

Liam

Posted 2015-11-27T22:55:41.513

Reputation: 3 035

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 – 2015-11-28T01:41:16.677

It doesn't on my computer (using g++) although int main(){main();} does cause a seg fault. – Liam – 2015-11-28T01:42:49.183

@VoteToClose I believe that tail recursion gets optimized away. – Maltysen – 2015-11-28T01:46:17.673

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 – 2015-11-28T01:50:55.780

Okay so it does crash eventually. That makes sense. If that's an issue, it isn't too hard to change it to a loop for a few extra bytes – Liam – 2015-11-28T01:50:59.387

¯\(ツ)/¯ I don't really see a problem with 11.1111... hours of runtime max. – Addison Crump – 2015-11-28T01:56:32.087

1With 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 – 2015-11-28T02:09:19.087

You can #include<cstdio> instead of stdio.h. – user8397947 – 2016-05-31T00:52:52.310

2

Ruby, 25 24 bytes

Thanks @manatwork for golfing off a byte :P

loop{puts`date;sleep 1`}

Not bad.

a spaghetto

Posted 2015-11-27T22:55:41.513

Reputation: 10 647

print? Either puts or $><< are shorter with identical result. – manatwork – 2015-11-29T15:29:59.107

Derp. Thanks for that. (You can tell I don't use Ruby much :P) – a spaghetto – 2015-11-29T15:55:46.833

2

Vimscript, 44 bytes

while 1
echo strftime("%T")
sleep 1
endwhile

Run like so:

vim -c ":so FILE"

a spaghetto

Posted 2015-11-27T22:55:41.513

Reputation: 10 647

2

PHP, 33 bytes

<?for(;;)sleep(print date("r
"));

Output is similar to Sat, 28 Nov 2015 11:25:16 +0700, i.e. RFC 2822.

primo

Posted 2015-11-27T22:55:41.513

Reputation: 30 891

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 – 2015-11-30T14:24:29.050

Are you invoking from the command line, e.g. php time.php? – primo – 2015-11-30T16:36:04.723

2

Go, 64 69 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++{ ... }.

cat

Posted 2015-11-27T22:55:41.513

Reputation: 4 989

1

This sleeps for one nanosecond, which results in multiple outputs per second. You'll need Sleep(Second) to fix this.

– Michael Hampton – 2015-11-28T08:55:50.393

1Sleep(1e9) would work, no? I don't remember very much about Go, but I remember something like that. – Addison Crump – 2015-11-28T11:05:55.407

@MichaelHampton fixed, thanks – cat – 2015-11-28T14:03:45.923

1@VoteToClose Yes, 1e9 works fine on my cgo 1.5.1... – Michael Hampton – 2015-11-28T14:05:33.707

I'm sitting at a PC so I can test it; it works. – cat – 2015-11-28T14:06:19.477

1Woo, helped golf a language I've never used! \o/ – Addison Crump – 2015-11-28T14:06:55.050

@VoteToClose The funny part is that gofmt puts all the whitespace back in, so Go never wins these sorts of competitions. Then again, it's a very readable language, and lots of fun to work with. – Michael Hampton – 2015-11-28T14:09:20.880

No, Go never wins [tag:code-golf] because every program starts with package main\nfunc main () {\n, not because it's beautiful and readable when formatted. I write my Go using lint-on-save and then golf it manually. – cat – 2015-11-28T14:11:23.980

1Well yes, that too. I'm using syntastic and vim-go, which has about the same result... – Michael Hampton – 2015-11-28T14:12:43.523

1At least it's not Java. – Addison Crump – 2015-11-28T14:12:51.887

2

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!

Dennis

Posted 2015-11-27T22:55:41.513

Reputation: 196 637

2

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

Brian

Posted 2015-11-27T22:55:41.513

Reputation: 1 209

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 – 2015-11-28T14:46:06.543

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 – 2015-11-28T15:04:26.373

2

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);
}

Paŭlo Ebermann

Posted 2015-11-27T22:55:41.513

Reputation: 1 010

Is n=now saving you bytes if you only use it once? I don't know Ceylon, but it seems redundant. – cat – 2015-11-29T15:58:01.773

1@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 – 2015-11-29T19:02:00.700

2

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.

6infinity8

Posted 2015-11-27T22:55:41.513

Reputation: 371

Can you show an example output? :D – Addison Crump – 2015-11-28T21:40:22.543

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 – 2015-11-28T21:44:21.857

Oh, so it's not graphical output? – Addison Crump – 2015-11-28T21:45:00.190

No, that's printed in the console. I'm just "exploiting" the draw method as a loop. – 6infinity8 – 2015-11-28T22:13:14.487

1Ohh, I see. Well done, +1 (in about an hour - can't vote right now. :c) – Addison Crump – 2015-11-28T22:13:54.313

2

Hassium, 43 Bytes

func main(){print(time())sleep(1000)main()}

See expanded here

Jacob Misirian

Posted 2015-11-27T22:55:41.513

Reputation: 737

2

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.

user19214

Posted 2015-11-27T22:55:41.513

Reputation:

2

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.").

jfs

Posted 2015-11-27T22:55:41.513

Reputation: 209

2

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.

jfs

Posted 2015-11-27T22:55:41.513

Reputation: 209

2

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

Fozzedout

Posted 2015-11-27T22:55:41.513

Reputation: 121

ForEver? Seems legit. – Addison Crump – 2015-12-01T10:24:03.970

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 – 2015-12-02T11:57:04.020

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 – 2015-12-02T11:58:29.730

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 – 2015-12-03T14:42:43.643

2

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

Emigna

Posted 2015-11-27T22:55:41.513

Reputation: 50 798

2

Vitsy + bash, 13 11 bytes

This language feature was made after this question, but not for this question.

&ltw1Z,'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!

Addison Crump

Posted 2015-11-27T22:55:41.513

Reputation: 10 763

sleep 1 based answer break rule 5: you must guarantee one, and only one, output of time per second... anymore!! – F. Hauri – 2016-05-18T06:44:01.777

@F.Hauri Please read rule 6 - also, stop spamming me. – Addison Crump – 2016-05-18T06:45:11.143

2

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.

steenbergh

Posted 2015-11-27T22:55:41.513

Reputation: 7 772

2

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.

cat

Posted 2015-11-27T22:55:41.513

Reputation: 4 989

2

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().

TheInitializer

Posted 2015-11-27T22:55:41.513

Reputation: 829

2

Emacs Lisp, 83 bytes

(run-with-timer 1 1(lambda()(message(format-time-string"%H:%M:%S"(current-time)))))

Lord Yuuma

Posted 2015-11-27T22:55:41.513

Reputation: 587

2

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.

ormaaj

Posted 2015-11-27T22:55:41.513

Reputation: 153

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 – 2015-12-16T14:26:53.790

@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 – 2015-12-16T15:11:02.847

2

Groovy, 40 37 bytes

Not very golfable :(, thanks to FlagAsSpam for for(;;) :)

for(;;){print(new Date());sleep 1000}

Fels

Posted 2015-11-27T22:55:41.513

Reputation: 488

1for(;;){...? And what about 1e3 for 1000? You can use print instead of println. – Addison Crump – 2015-12-16T14:30:13.867

Thanks, I was pretty sure it needs to be a new line every time. – Fels – 2015-12-16T14:36:54.067

2

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

MemoryPenguin

Posted 2015-11-27T22:55:41.513

Reputation: 121

+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 – 2016-05-23T06:49:59.077

2

MATL, 11 bytes

`Z'0XOD1Y.T

Try it here.

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

Luis Mendo

Posted 2015-11-27T22:55:41.513

Reputation: 87 464

Why non competing? – Socratic Phoenix – 2016-07-31T16:43:21.990

@SocraticPhoenix Becuase the language is newer than the challenge. I've clarified that in the answer – Luis Mendo – 2016-07-31T17:06:36.850

unless I'm mistaken, this is a catalog challenge, meaning you can post languages that are newer... – Socratic Phoenix – 2016-07-31T19:27:52.533

Yep, "Since this is a catalog, languages created after this challenge are allowed to compete" – Socratic Phoenix – 2016-07-31T19:28:15.470

@SocraticPhoenix Oh, thanks! I hadn't noticed. I'll remove the note then – Luis Mendo – 2016-07-31T21:52:37.813

2

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!

cat

Posted 2015-11-27T22:55:41.513

Reputation: 4 989

2

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.

Roujo

Posted 2015-11-27T22:55:41.513

Reputation: 353

1Few 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 – 2016-02-02T21:42:57.727

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 – 2016-02-02T21:46:14.757

1while (truthy value)? – Rɪᴋᴇʀ – 2016-02-02T21:48:36.713

@RikerW Right, that's another good one. I usually write infinite loops as recursive functions, so I hadn't thought about it. Thanks! =) – Roujo – 2016-02-02T21:51:02.027

Not just plain 1? – Rɪᴋᴇʀ – 2016-02-02T21:58:00.360

@RikerW Because of F#'s strong typing, that doesn't work. The only truthy value is true, of type bool. Anything else won't type-check - if I put in while 1 do, I get this error: stdin(1,7): error FS0001: This expression was expected to have type bool but here has type int. – Roujo – 2016-02-02T21:59:52.153

Okay, just checking. So 1=1 is the shortest possible. – Rɪᴋᴇʀ – 2016-02-02T22:24:41.940

Does Threading.Thread.Sleep 1e3 work? – Addison Crump – 2016-02-02T23:30:29.113

@VoteToClose I didn't know if 1e3 was valid F#, so I tried it just now. Turns out that it works! Well, kinda - it evaluates to 1000.0, but Sleep doesn't have an overload that takes a float. Still, I learned something new! =) – Roujo – 2016-02-03T14:43:20.267

2

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;}

F. Hauri

Posted 2015-11-27T22:55:41.513

Reputation: 2 654

Woah, thems be some complicated bash – Addison Crump – 2016-05-17T20:17:13.250

Yes, but without any external binary! (even no sleep) – F. Hauri – 2016-05-30T22:36:29.157

2

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]

draegtun

Posted 2015-11-27T22:55:41.513

Reputation: 1 592

2Lol, is it said that I read this like house music? Print, now wait 1. Print, now wait 1. – Addison Crump – 2016-05-20T09:35:10.497

2

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.

Drew Christensen

Posted 2015-11-27T22:55:41.513

Reputation: 159

1I 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 – 2016-05-31T00:42:24.827

Welcome to PPCG! – NoOneIsHere – 2016-05-31T04:09:40.003

1

tcl, 67

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

can be tested on: http://www.tutorialspoint.com/execute_tcl_online.php?PID=0Bw_CjBb95KQMUkViT2lXWDlLYlE

sergiol

Posted 2015-11-27T22:55:41.513

Reputation: 3 055

1

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

Carcigenicate

Posted 2015-11-27T22:55:41.513

Reputation: 3 295

1

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)

steenbergh

Posted 2015-11-27T22:55:41.513

Reputation: 7 772

1

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

pppery

Posted 2015-11-27T22:55:41.513

Reputation: 3 987

1

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.

lirtosiast

Posted 2015-11-27T22:55:41.513

Reputation: 20 331

I count 65 bytes there... how do you get 29? – Fozzedout – 2015-12-01T10:08:02.433

1@Fozzedout TI-BASIC uses a tokenized encoding of one or two bytes per token. – Adám – 2016-02-01T19:18:37.860

1

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);
        }
    }
}

gamesmad

Posted 2015-11-27T22:55:41.513

Reputation: 111

1I don't know C# but can't you do for(;;) instead of while(true)? – Blue – 2015-11-30T09:45:32.487

Updated, thanks @muddyfish – gamesmad – 2015-11-30T10:13:25.983

1Can you do 1e3 over 1000? (I don't know C# either.) – Addison Crump – 2015-11-30T10:15:23.853

Thread.Sleep accepts either int or TimeSpan. You can do Thread.Sleep((int)1e3) but that's longer unfortunately. – gamesmad – 2015-11-30T10:18:45.530

1

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.

insertusernamehere

Posted 2015-11-27T22:55:41.513

Reputation: 4 551

"You must output the current time continuously (until cancelled by an interrupt), once every second" ... not every millisecond. – None – 2015-11-30T15:43:27.253

1@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 – 2015-11-30T15:46:57.470

2Changing the rules in comments is not a good idea... he better should update the original text instead... :-( – None – 2015-11-30T15:57:37.090

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 – 2016-08-26T22:13:34.690

1

@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 – 2016-08-26T22:20:31.057

Good to know, I will be 2 bytes better on most challenges from now on! – YetiCGN – 2016-08-26T22:25:17.503

1

AppleScript, 112 93 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.

Addison Crump

Posted 2015-11-27T22:55:41.513

Reputation: 10 763

sleep 1 based answer break rule 5: you must guarantee one, and only one, output of time per second!! – F. Hauri – 2016-05-18T06:41:53.793

@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 – 2016-05-18T06:44:34.030

1

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.

cat

Posted 2015-11-27T22:55:41.513

Reputation: 4 989

1

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.

Dennis

Posted 2015-11-27T22:55:41.513

Reputation: 196 637

1

Factor, 43 bytes

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

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

cat

Posted 2015-11-27T22:55:41.513

Reputation: 4 989

1

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.

user47018

Posted 2015-11-27T22:55:41.513

Reputation:

This not seems to output the time continuously, once per second. – manatwork – 2016-03-30T16:48:19.743

Fixed the problem! – None – 2016-03-30T17:12:41.840

1

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.

m654

Posted 2015-11-27T22:55:41.513

Reputation: 765

1

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.

m654

Posted 2015-11-27T22:55:41.513

Reputation: 765

"Since this is a catalog, languages created after this challenge are allowed to compete." Hey, what are you waiting for? – user48538 – 2016-05-20T09:41:05.167

@zyabin101 Fixed that! Thanks :) – m654 – 2016-05-20T11:36:45.877

1

Scratch, 15 bytes

Scratch Script
(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.

weatherman115

Posted 2015-11-27T22:55:41.513

Reputation: 605

1Hello, and welcome to PPCG! According to Meta, that is 15 bytes, one for each block, and one for each character of text. – NoOneIsHere – 2016-05-18T20:05:19.147

Thanks for pointing that out, I linked the meta post in question for clarity. – weatherman115 – 2016-05-18T22:54:32.980

1

Mathematica, 27 21 bytes

With 2 bytes saved thanks to Xavier.

Dynamic@{Now,Clock[]}

DavidC

Posted 2015-11-27T22:55:41.513

Reputation: 24 524

25 bytes with Dynamic@{Now,Clock@{1,2}}, and 21 with: Dynamic@{Now,Clock[]}. – None – 2016-08-27T14:59:13.203

1

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

Katenkyo

Posted 2015-11-27T22:55:41.513

Reputation: 2 857

1

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.

Scepheo

Posted 2015-11-27T22:55:41.513

Reputation: 466

1

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.

Beta Decay

Posted 2015-11-27T22:55:41.513

Reputation: 21 478

0

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

Erik the Outgolfer

Posted 2015-11-27T22:55:41.513

Reputation: 38 134

0

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

Taylor Scott

Posted 2015-11-27T22:55:41.513

Reputation: 6 709

0

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.

Copper

Posted 2015-11-27T22:55:41.513

Reputation: 3 684

0

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.

Updates:

  1. Removed short open tag as per this meta answer

YetiCGN

Posted 2015-11-27T22:55:41.513

Reputation: 941

for(;;sleep(1))... saves three bytes. echo date("\nr"); is not shorter, but looks cleaner imo. – Titus – 2017-01-07T11:42:48.090

0

05AB1E, 13 bytes

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

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

acrolith

Posted 2015-11-27T22:55:41.513

Reputation: 3 728

0

Elixir, 95 bytes

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

Flow

Posted 2015-11-27T22:55:41.513

Reputation: 39