Output the current time of day as Swatch Internet Time.

Specifically, output a three-digit (zero-padded) number of ".beats" (1000ths of a day) which represent the current time of day in the Swatch Internet Time time zone of UTC+01:00 ("Biel Meantime").

For example, if the current time in UTC is 23:47, then it is 00:47 in UTC+1 ("Biel Meantime"), and the output would be 032.


UTC Current Time  ->  SIT Output
23:47             ->  032
23:00             ->  000
11:00             ->  500
14:37             ->  651

The program should produce this output then immediately exit.

Output is to standard output (or equivalent). Must be a complete, runnable program, not a function. The program takes no input; it outputs the current time.

  • 4
    \$\begingroup\$ Possible dupe? From reading the article it looks like doing a minor amount of arithmetic on the output to that challenge. Perhaps if you described the intricacies of Swatch Internet Time within the post, it would be clearer whether or not this is a duplicate. That said, welcome to PPCG, I hope your first question goes well, but note we have a sandbox where challenges can be posted for review. \$\endgroup\$ Jul 10 '16 at 23:59
  • 2
    \$\begingroup\$ SE policy is that I should not need to visit external sites to understand and answer your question and the same goes for challenges. I don't know what SIT is, and when the thing hosting your link blows up, neither will anyone else. \$\endgroup\$
    – cat
    Jul 11 '16 at 1:29
  • 2
    \$\begingroup\$ Some more sample inputs and outputs would be nice. This challenge might have been better were it steeped in the Sandbox \$\endgroup\$
    – cat
    Jul 11 '16 at 1:29
  • 1
    \$\begingroup\$ What sort of precision is required? Minute, hour, second ... for example if it is second, I need a factor of 0.69444 while for minutes 0.694 is sufficient (assuming a floored int as output) \$\endgroup\$
    – MickyT
    Jul 11 '16 at 2:25
  • 2
    \$\begingroup\$ @R.Kap I agree with your points a) and b), but it's obvious that if SIT is based on UTC+1 and it's currently 23:47 UTC(+0), it's 00:47 UTC+1, which agrees with Andrea's example. Hopefully we can get the question clarified, because I don't think it's a duplicate of the Current Time question. \$\endgroup\$
    – beaker
    Jul 11 '16 at 20:12

16 Answers 16


PHP, 12 bytes


But it can only be so short because PHP has built-in Swatch Internet Time support. So this answer isn't much fun.

<?= exits HTML mode and evaluates an expression, then echoes it.

@ silences an error.

date() outputs the current time, formatting it with a given format string.

B is an undefined constant. In PHP, if you reference a constant that doesn't exist, you get back a string containing its name, and it also produces a “notice”-level error. Here, the @ suppresses that error. B is the date() format code for Swatch Internet Time.

; terminates the expression.

If we assume PHP is being run with the default error-reporting settings, where “notices” are silenced, we could skip the @, and it would only be 11 bytes.

  • 3
    \$\begingroup\$ I'm pretty sure supresssing notices is actually the default for PHP golfing on this site \$\endgroup\$ Jul 16 '16 at 3:12
  • \$\begingroup\$ @SuperJedi224 It's PHP's default configuration, too, but I have it set to show notices on my machine, so… \$\endgroup\$
    – Andrea
    Jul 17 '16 at 15:09

C, 56 bytes

  • %03d - tells printf to zero-pad up to 3 digits.
  • time(NULL)+3600 - gets amount of seconds (UTC) elapsed since epoch and adds an hour to it (UTC+1).
  • %86400 - divides epoch by the amount of seconds in a 24hr day and gets the remainder (representing seconds elapsed, so far, "today").
  • /86.4 - divide remaining seconds by 86.4 to get the ".beat" count since midnight (UTC+1).

Compile (MSVC):

C:> cl swatch.c

Compile (GCC):

$ gcc swatch.c

  • \$\begingroup\$ For future reference: you should post the golfed version of the code, and, at your option, an ungolfed version or test program below. \$\endgroup\$
    – cat
    Jul 11 '16 at 12:09
  • \$\begingroup\$ This contains a bug. It doesn't do a modulo after correcting the time-zone, it does it before, which means between 23:00–0:00 UTC (i.e. 0:00–1:00 UTC+1), it incorrectly produces a four-digit number. You could fix this by changing time(NULL)%86400+3600 to (time(NULL)+3600)%86400. \$\endgroup\$
    – Andrea
    Jul 13 '16 at 20:50
  • \$\begingroup\$ Also, you could save space by omitting the two includes, and replacing the NULL with 0. \$\endgroup\$
    – Andrea
    Jul 13 '16 at 20:51
  • \$\begingroup\$ Hmm, doesn't %03.f round up? That would give inaccurate results. \$\endgroup\$
    – Andrea
    Jul 16 '16 at 0:22
  • \$\begingroup\$ @Andrea Thank you. Edited. \$\endgroup\$
    – veganaiZe
    Jul 24 '16 at 22:03

PHP, 48 46 bytes


I have another PHP answer above, but this one avoids using PHP's built-in Swatch Internet Time support, so it's more interesting, if longer.

This is largely self-explanatory if you're familiar with UNIX time and sprintf, though note I'm using |0 as a short way to truncate a float to an integer (actually I realised this is unnecessary in PHP, oops!)


Java 8, 143 bytes

import java.time.*;interface A{static void main(String[]a){System.out.format("%03.0f",LocalTime.now(ZoneId.of("UT+1")).toSecondOfDay()/86.4);}}

this uses Java 8's java.time package to get current time, convert it to UTC+1, and then get the number of seconds. At the end it divides by the number of 1000s of seconds in a day, which turns out to be 86.4.

Funny how the function that actually calculates the time is only about a third of the overall program size.


Javascript, 53 52 bytes


Shortened by using Date.now().

new Date() is the current date. Subtracting from it treats it as milliseconds since the Unix epoch. Subtracting 828e5 is subtracting 23 hours, which, when ignoring the day, is the same as adding 1 to the hour, or moving from UTC+0 to UTC+1.
Date.now() is the current date in milliseconds since the Unix Epoch. Adding 36e5 moves from UTC+0 to UTC+1.
This new value is divided by 864e5 to change it from milliseconds to days. Then the modulus of it and 1 is taken, meaning the result is a number between 0 (inclusive) and 1 (exclusive) showing the progress through the day.
"0000" is concatenated with this, turning it into a string. Then the 3rd through 5th characters are taken. The reason "0000" is concatenated instead of an empty string is for the cases in which there are fewer than 3 decimal places:

  • "0.XXX(any number of digits here)0000" Swatch time is XXX
  • "0.XX0000" Swatch time is XX0
  • "0.X0000" Swatch time is X00
  • "00000" Swatch time is 000

05AB1E, 29 21 bytes


After compressing integers thanks to @KevinCruijssen (-8 bytes) :



ža                               push current hours in UT 
  >                              increment
   60©                           push 60 and save in register c
      %                          hours mod 60
       ®*                        push from register c and Multiply
         žb+                     add current minutes    
            ₄*                   multiply by 1000
              1440÷              Integer division with 1440
                   D             Duplicate
                    g            Length
                     3s-         3-length
                        Å0       create list of a 0s
                          š      Prepand
                           ˜J    Flat and joon

I didn't find a better idea for prepanding Zeros, so if anyone got a better idea I'll be glad to know :)

Try it online!

Try the 21 bytes online!

  • \$\begingroup\$ The output of this is not three padded digits, no? \$\endgroup\$
    – Andrea
    Jul 30 '20 at 12:49
  • 1
    \$\begingroup\$ I've edited my answer \$\endgroup\$
    – SomoKRoceS
    Jul 30 '20 at 13:44
  • 1
    \$\begingroup\$ Yes :) it prints the current swatch time, I pushed the current hours in UTC and Incremented it (mod 24). \$\endgroup\$
    – SomoKRoceS
    Jul 30 '20 at 21:52
  • 2
    \$\begingroup\$ The “tio.run” output I was looking at was outdated and just so happened to be exactly an hour behind! Clicking the big ▶️ button re-ran it and I see your code is correct, sorry! \$\endgroup\$
    – Andrea
    Jul 31 '20 at 9:00
  • 1
    \$\begingroup\$ 1440 can be compressed to Ž5¦ (see section How to compress large integers? in this 05AB1E tip of mine). As for the Dg3s-Å0š˜J, this can be golfed to ₄+¦ (add 1000, remove the first character). \$\endgroup\$ Oct 21 '20 at 12:44

JavaScript, 98 bytes

d=new Date();t=;console.log(Math.floor((360*d.getHours()+60*d.getMinutes()+d.getSeconds())/86.4));

Definitely could be optimized, I had some problems with the Date object so I'm looking into shorter ways to do that.

  • \$\begingroup\$ Hmm. You could probably be more efficient by using the UNIX timestamp feature (Date.prototype.getTime), instead of summing the hours, minutes and seconds. Also, though I didn't make this clear before, I think the output should be zero-padded. \$\endgroup\$
    – Andrea
    Jul 13 '16 at 20:45

Octave, 64 bytes


Uses veganaiZe's printf formatting.

I'm having a bit of difficulty with the time that ideone is returning, so here's a sample run with the time struct returned by gmtime for reference. I'll look around and see if I can get any of the other online Octave compilers to give me proper time.

t =    
  scalar structure containing the fields:
    usec =  528182
    sec =  17
    min =  24
    hour =  21
    mday =  15
    mon =  6
    year =  116
    wday =  5
    yday =  196
    isdst = 0
    zone = UTC

ans = 933

q/k (21 bytes)


Python 2.7, 131 128 121 bytes:

from datetime import*;S=lambda f:int(datetime.utcnow().strftime(f));print'%03.0f'%(((S('%H')+1%24)*3600+S('%M')*60)/86.4)

A full program that outputs the Swatch Internet Time.

Simply uses Python's built in datetime module to first get the UTC+0 time in hours and minutes using datetime.utfnow().strftime('%H') and datetime.utfnow().strftime('%M'), respectively. Then, the time is converted into UTC+1 by adding 1 to the hours and then modding the sum by 24 to ensure the result is in the 24-hour range. Finally, the hour is turned into its equivalent in seconds, which is added to the minute's equivalent in seconds, and the resulting sum is divided by 86.4, as there are 86.4 seconds or 1 min. 24 sec. in 1 ".beat", after which, using string formatting, the quotient is rounded to the nearest integer and padded with zeroes until the length is 3.

However, I am not the one to stop here. In the above solution, I used a more direct method to convert the time to UTC+1. However, wanted to add a bit of a bigger challenge for myself and implement this using only Python's built in time module, which apparently does not have any built-in method that I know of to convert local time into UTC+0 time. So now, without further ado, here is the perfectly working version using only the time module, currently standing at 125 bytes:

from time import*;I=lambda g:int(strftime(g));print'%03.0f'%((((I('%H')+1-daylight)%24*3600+timezone)%86400+I('%M')*60)/86.4)

This can output the correct Swatch Internet Time for any and all time zones, and basically does pretty much everything the same as in the first solution, except this time converts the local time into UTC+1 by first adding 1 to the hour, and then subtracting 1 if daylight-savings time is currently, locally observed, or 0 otherwise. Then, this difference is modded by 24 to ensure that the result stays within the 24 hour range, after which it is multiplied by 3600 for conversion into seconds. This product is then added to the result from the built-in timezone method, which returns the local offset from UTC+0. After this, you finally have your hours in UTC+1. This then continues on from here as in the first solution.

  • \$\begingroup\$ Interesting! Though, it shouldn't be necessary to get this from stdin, given Python knows the current time, right? \$\endgroup\$
    – Andrea
    Jul 15 '16 at 23:52
  • \$\begingroup\$ @Andrea It is fixed and works perfectly now. \$\endgroup\$
    – R. Kap
    Jul 16 '16 at 8:50
  • \$\begingroup\$ Hmm, intriguing. Might it be shorter using UNIX time? \$\endgroup\$
    – Andrea
    Jul 17 '16 at 15:11

Javascript, 83 bytes

a=(((36e5+(+new Date()))%864e5)/864e2).toFixed(),alert("00".slice(Math.log10(a))+a)

CJam, 34 bytes

Update: I shouldn't code hungry. My previous answer was shorter, but didn't cast to int or left-pad. These are now fixed, with +8 bytes to left-pad (probably improvable), +1 to int cast, and -2 to optimizations. My old comment no longer applies.


Try it online


r                   read input
 ':/                split on :
    ~               unwrap array
     \~             evaluate hour to numbers
       )            increment hour
        24md        modulo 24
            60*     multiply by 60
               @~   switch to minute and eval to num
+                   add hour*60 and minute
 1.44/              divide by 1.44 to get SIT
      i             cast to int
       "%03d"e%     format as 3 leading 0s
               o;   output and discard spare 0 from modulo
  • \$\begingroup\$ I suppose the first three digits are correct, so maybe it's a valid entry in that way (I never said a newline was required…) but it's not supposed to have a decimal point or any fractional digits. \$\endgroup\$
    – Andrea
    Jul 26 '20 at 21:49
  • \$\begingroup\$ Oops, I missed that no decimal requirement. I have other optimizations I thought of in the last half-hour, so I'll just add a cast to int along with those. \$\endgroup\$ Jul 26 '20 at 22:18
  • \$\begingroup\$ @Andrea I missed the leading 0s requirement, so that's fixed as well. There may be a better way but I'm not very familiar with that part of CJam. \$\endgroup\$ Jul 26 '20 at 22:36

Japt, 27 23 19 15 bytes

Kj z86400 s t3n

Test it

Javascript port.

I hope I've done it correctly.

-4 bytes from Shaggy.

-4 more bytes from Shaggy.

-4 more more bytes from Shaggy.

  • \$\begingroup\$ I'm not entirely sure I've understood the challenge but this definitely isn't right; you need a space before the / and the t2,3 should be at the end, with a space before it, giving Kj +36e5 /864e5%1+"0000" t2,3. And, from there, you can get down to 23 bytes with 36e5+Kj)/864e5%1 x4 ¤¯3. When I figure the challenge out, I'll see if any more can be saved. \$\endgroup\$
    – Shaggy
    Oct 20 '20 at 11:41
  • 1
    \$\begingroup\$ OK, think I've figured it out and you should be able to get down to at least 21 bytes by: claiming locale dependency (i.e., a UTC+1 timezone), getting the current hour, multiplying by 60, adding the minutes, floor dividing by 1.44, converting to a string and then left padding with 0s. \$\endgroup\$
    – Shaggy
    Oct 20 '20 at 15:00
  • 1
    \$\begingroup\$ Oh, and welcome to Japt :) \$\endgroup\$
    – Shaggy
    Oct 20 '20 at 15:01
  • \$\begingroup\$ Actually, feck that, just knock the first 5 bytes off the current version for 18 bytes. Dunno why I was trying to overcomplicate it! \$\endgroup\$
    – Shaggy
    Oct 20 '20 at 15:35
  • \$\begingroup\$ @Shaggy wait, knocking that off is to claim locale dependency, correct? \$\endgroup\$
    – Razetime
    Oct 20 '20 at 15:37

Python 3, 68 bytes

import time

Try it online!

  • \$\begingroup\$ This seems to be rounded differently than PHP's date("B"); but I guess it's close enough? (I don't know what the PHP code does, I'm guessing this is a ceil versus floor difference, or your constants aren't precise enough) \$\endgroup\$
    – Andrea
    Oct 22 '20 at 20:33
  • 1
    \$\begingroup\$ @Andrea the difference is probably that I'm using only the hour and minute specifiers, whereas I'm guessing the php implementation uses a more precise value. My approach is rounded down to the minute, as per all the test cases. \$\endgroup\$
    – Jitse
    Oct 22 '20 at 21:56
  • \$\begingroup\$ Fair enough! Swatch Internet Time is not very precise so I won't be pedantic over precision if it's only off by ±1. \$\endgroup\$
    – Andrea
    Oct 23 '20 at 21:42

C#, 112 bytes

class P{static void M(){System.Console.Write((int)((DateTime.UtcNow.TimeOfDay.TotalSeconds%86400+3600)/86.4));}}

C#, 68 bytes


A simple port of @veganaiZe's code. Thanks to him :)

Try it online!

  • \$\begingroup\$ Is this a "complete and runnable program"? I don't know much C#, but this looks like a lambda than a full program. \$\endgroup\$
    – user55852
    Jul 18 '16 at 0:19
  • \$\begingroup\$ @YakovLipkovich Lambda are allowed on PPCG. Well I saw that here, in this specific question, they aren't. I asked why. \$\endgroup\$
    – aloisdg
    Jul 18 '16 at 3:17
  • \$\begingroup\$ Since this adds 3600 after doing the modulo, won't it return the wrong result after 23:00 UTC? \$\endgroup\$
    – Andrea
    Sep 5 '16 at 18:53
  • \$\begingroup\$ @Andrea Maybe indeed. Did you try it after 23h? \$\endgroup\$
    – aloisdg
    Sep 8 '16 at 8:11
  • \$\begingroup\$ @aloisdg I haven't tried your code yet, but it should be clear this will happen without running it. \$\endgroup\$
    – Andrea
    Sep 9 '16 at 3:33

Common Lisp (Lispworks), 144 bytes

(defun f(s)(let*((d(split-sequence":"s))(h(parse-integer(first d)))(m(parse-integer(second d))))(round(/(+(*(mod(1+ h) 24)3600)(* m 60))86.4))))


    (defun f (s)
      (let* ((d (split-sequence ":" s))
             (h (parse-integer (first d)))
             (m (parse-integer (second d))))
            (mod (1+ h) 24)
           (* m 60))


CL-USER 2759 > (f "23:47")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.