20
1
Display a Digital Clock
(I see there are many clock challenges, I have tried to read them all, I'm pretty sure this is unique)
Write some code that continuously updates a digital clock displayed in the format h:m:s
where h
, m
, and s
can occupy 1 or 2 characters each. The restrictions in simple terms as @BlueEyedBeast put it, I basically want it to replace the time shown.
- Newlines are not allowed
- Trailing spaces are allowed
- Other trailing characters are not allowed
- No seconds should be missed (57 -> 59 is not allowed)
- Numbers beginning with "0" are allowed, as long as they don't occupy more than 2 characters
- The code must not accept any input
- If your language can't get the current time without input, you may use for input up to 8 bytes in a standardly allowed way
- Output must be to stdout
- This is codegolf so the shortest answer wins!
Example
I'm working on a language named *><> (starfish) because programs like this aren't possible in ><> (just wait for file i/o) . Here's a working digital clock program in it (ungolfed). This program is written in *><>:
s":"m":"hnonon" "ooo88888888888ooooooooooo1S
Note: Everything is identical to ><> in this except, s = second, m = minute, h = hour, S = sleep(100ms*x)
This outputs:
14:44:31
Updating every 100ms until terminated.
Disallowed Examples
The following are not allowed:
1:
14:44:3114:44:32
2:
14:44:31 14:44:32
3:
14:44:31
14:44:32
The time must remain on the first line it was outputted with no visible trailing characters. Clearing the terminal though, would be allowed as that still wouldn't have any trailing characters.
1do we have to wait 100ms or can we just update constantly forever? – Blue – 2016-12-05T21:42:46.060
1you don't have to wait, the wait is just what the example does. – redstarcoder – 2016-12-05T21:43:10.150
2The challenge requirements seem too strict to me. – mbomb007 – 2016-12-05T21:50:12.063
I just thought without restricting the output this would have been too easy. There are a multitude of ways to write the time to one line. Why is this too strict? – redstarcoder – 2016-12-05T21:55:15.777
1@mbomb007 I removed "The program must be able to exit on user input that isn't a signal/interrupt" as the current answers didn't seem to follow it anyways. – redstarcoder – 2016-12-05T22:05:13.220
Does it have to be in local time? – Winny – 2016-12-06T03:49:32.837
How does your example program stop when enter key is hit? Is it the
S
? And why do you print three spaces after the time? (Just curiosities) – Leo – 2016-12-06T07:54:42.4871Can the program rely on a specific local setting of the OS? – raznagul – 2016-12-06T17:01:41.427
@Leo ah an older revision did that. I updated the description to no longer say it exits on enter (It used to have
i1+?;
or something). – redstarcoder – 2016-12-06T18:23:35.720@Winny, it can be any timezone as long as it's actually the time (or at least reasonably close, so it can be used to tell time). – redstarcoder – 2016-12-06T18:24:27.837
1@raznagul, I'm not sure what you mean, do you have an example? I'll probably allow it. – redstarcoder – 2016-12-06T18:25:07.580
1@redstarcoder: In C#
DateTime.Now.ToString("T")
would return19:43:16
on my PC as the region setting is set to Germany. But on a PC with a region setting of US the result would be7:43:16 PM
. – raznagul – 2016-12-06T18:45:20.7301@raznagul, that's fine, just specify the conditions to make your output valid! – redstarcoder – 2016-12-06T19:05:23.740
Isn't this the same as "output the current time"? I'm on a phone so cant edit a link, sorry – ev3commander – 2016-12-14T23:54:32.167
@ev3commander it's similar, but not the same. – redstarcoder – 2016-12-15T00:53:44.317