Skip to main content
for-loop with sleep(1)
Source Link
LukeS
  • 441
  • 3
  • 5

Julia 0.6, 7575 68 bytes

for h=0:23,m=0:59,s=0:59;@printf "%02i:%02i:%02i
" h m s;sleep(1)end

Try it online!

With sleep(1) allowed, simple nested for-loops are shorter than using Julias built-in time handling methods.

Old solution without sleep(1) using DateTime

t=now()-DateTime(0);Timer(x->println(Dates.format(now()-t,"HH:MM:SS")),0,1)

t is the amount of time passed from 'day 0' to when the program is started. now()-t is a moment in time, which is then formatted using Dates.format().

t0=now(); ...; now()-t0 would yield a time difference, that cannot be used with Dates.format().

The timing itself is trivial with the build-in Timer.

Julia 0.6, 75 bytes

t=now()-DateTime(0);Timer(x->println(Dates.format(now()-t,"HH:MM:SS")),0,1)

t is the amount of time passed from 'day 0' to when the program is started. now()-t is a moment in time, which is then formatted using Dates.format().

t0=now(); ...; now()-t0 would yield a time difference, that cannot be used with Dates.format().

The timing itself is trivial with the build-in Timer.

Julia 0.6, 75 68 bytes

for h=0:23,m=0:59,s=0:59;@printf "%02i:%02i:%02i
" h m s;sleep(1)end

Try it online!

With sleep(1) allowed, simple nested for-loops are shorter than using Julias built-in time handling methods.

Old solution without sleep(1) using DateTime

t=now()-DateTime(0);Timer(x->println(Dates.format(now()-t,"HH:MM:SS")),0,1)

t is the amount of time passed from 'day 0' to when the program is started. now()-t is a moment in time, which is then formatted using Dates.format().

t0=now(); ...; now()-t0 would yield a time difference, that cannot be used with Dates.format().

The timing itself is trivial with the build-in Timer.

added 1 character in body
Source Link
LukeS
  • 441
  • 3
  • 5

Julia 0.6, 75 bytes

t=now()-DateTime(0);Timer(x->println(Dates.format(now()-t,"HH:MM:SS")),0,1)

t is the amount of time passed sincefrom 'day 0', to when the program is started. now()-t is a moment in time, which is then formatted using Dates.format().

t0=now(); ...; now()-t0 would yield a time difference, that cannot be used with Dates.format().

The timing itself is trivial with the build-in Timer.

Julia 0.6, 75 bytes

t=now()-DateTime(0);Timer(x->println(Dates.format(now()-t,"HH:MM:SS")),0,1)

t is the amount of time passed since 'day 0', when the program is started. now()-t is a moment in time, which is then formatted using Dates.format().

t0=now(); ...; now()-t0 would yield a time difference, that cannot be used with Dates.format().

The timing itself is trivial with the build-in Timer.

Julia 0.6, 75 bytes

t=now()-DateTime(0);Timer(x->println(Dates.format(now()-t,"HH:MM:SS")),0,1)

t is the amount of time passed from 'day 0' to when the program is started. now()-t is a moment in time, which is then formatted using Dates.format().

t0=now(); ...; now()-t0 would yield a time difference, that cannot be used with Dates.format().

The timing itself is trivial with the build-in Timer.

Source Link
LukeS
  • 441
  • 3
  • 5

Julia 0.6, 75 bytes

t=now()-DateTime(0);Timer(x->println(Dates.format(now()-t,"HH:MM:SS")),0,1)

t is the amount of time passed since 'day 0', when the program is started. now()-t is a moment in time, which is then formatted using Dates.format().

t0=now(); ...; now()-t0 would yield a time difference, that cannot be used with Dates.format().

The timing itself is trivial with the build-in Timer.