====== Swatch Internet Time / .beat Time ======
#beatTime#
===== How can I use swatch time in my life? =====
Easy; just use swatch time when you are planning your events or meetups and get your friends to do the same! There are even some apps that can help you!
**Swatch Time Apps for various platforms:**
* All Apple devices, including Apple Watch - [[https://beattime.mulot.org/|BeatTime]]
* Android Phones - [[https://f-droid.org/en/packages/eu.mirkodi.swatchbeatclock/index.html|Swatch .beat clock]], [[https://play.google.com/store/apps/details?id=xyz.poolp.swatchtime|Swatch Time]]
* Pebble Smart Watches - [[https://apps.rebble.io/en_US/search/watchfaces/1?native=false&query=beat|See Beat apps]]
* macOS Menubar - [[https://github.com/amiantos/dotbeat|dotbeat]]
* GNOME Extension - [[https://extensions.gnome.org/extension/5946/swatch-clock/|Swatch Clock]]
* Cinnamon Applet - [[https://cinnamon-spices.linuxmint.com/applets/view/310|Internet Time]]
* Win 95/XP - [[https://web.archive.org/web/20081224143907/http://www.artefakt.com/projects/ibeat/|iBeat]], Works with Wine and OS's running Windows 7+ as well, not guaranteed to work in the year 2038
* Winamp & WaCUP - [[https://getwacup.com/plugins/big_clock/|Big Clock]], Comes bundled with every copy of WaCUP (and Winamp, I think?), Right click on the big clock, then click on .beat time
* iPad - [[https://apps.apple.com/us/app/beat-internet-time/id1570173118|Beat: Internet time]]
* Color - [[rgbeat|RGBeat]], changes color depending on what time it is, in beat; [[https://melonking.net/hidden/rgbeat|Melon]], [[https://unnick.mice.tel/rgbeat/|Unick]]
===== Other useful links! =====
* Swatch time [[https://forum.melonland.net/index.php?topic=1202.0|discussion thread]] on our forum!
* The Swatch [[https://www.swatch.com/en-en/internet-time.html|intro video from 1998]]
* Swatch Time History on [[https://en.wikipedia.org/wiki/Swatch_Internet_Time|Wikipedia]]
* Decimal Time on Wikipedia [[https://en.wikipedia.org/wiki/Decimal_time]]
----
===== Code Snippets =====
You can also include a swatch clock on your website; here are some premade code snippets you can use!
==== JavaScript: ====
**JavaScript - Easy Option**
Here is a premade JavaScript clock for your website! Just paste this code onto your page wherever you want your clock to be and it will work!
@000
**JavaScript - Full Code**
// Returns the current Swatch beat
function GetSwatchTime(showDecimals = true) {
// get date in UTC/GMT
var date = new Date();
var hours = date.getUTCHours();
var minutes = date.getUTCMinutes();
var seconds = date.getUTCSeconds();
var milliseconds = date.getUTCMilliseconds();
// add hour to get time in Switzerland
hours = hours == 23 ? 0 : hours + 1;
// time in seconds
var timeInMilliseconds = ((hours * 60 + minutes) * 60 + seconds) * 1000 + milliseconds;
// there are 86.4 seconds in a beat
var millisecondsInABeat = 86400;
// calculate beats to two decimal places
if (showDecimals) {
return Math.abs(timeInMilliseconds / millisecondsInABeat).toFixed(2);
} else {
return Math.floor(Math.abs(timeInMilliseconds / millisecondsInABeat));
}
}
If you want it to display on your webpage and auto-update here is an example - first, we make a **span** with an id, this is where the clock will appear on your page - then we get that span in a script, make a function that fills it with the swatch time, and finally, we set it to reload every microbeat.
==== PHP: ====
PHP has native support for Swatch time, you can get the latest beat using this snippet:
$swatchTime = date('B'); //000-999
However if you would like a full function that also shows microbeats, we have that too!
// Returns the current Swatch beat
function GetSwatchTime($showDecimals = true)
{
// Get time in UTC+1 (Do not Change!)
$now = new DateTime("now", new DateTimeZone("UTC"));
$now->add(new DateInterval("PT1H"));
// Calculate the seconds since midnight e.g. time of day in seconds
$midnight = clone $now;
$midnight->setTime(0, 0);
$seconds = $now->getTimestamp() - $midnight->getTimestamp();
// Swatch beats in seconds - DO NOT CHANGE
$swatchBeatInSeconds = 86.4;
// Calculate beats to two decimal places
if ($showDecimals) {
return number_format(round(abs($seconds / $swatchBeatInSeconds), 2), 2);
} else {
return floor(abs($seconds / $swatchBeatInSeconds));
}
}
==== BASH: ====
(note that Etc timezones are inverted)
Calculating Beat Time in bash is simple:
MIDNIGHT=$( TZ='Etc/GMT-1' date -d "12:00 am" +%s )
BTIME=$(( (($EPOCHSECONDS - $midnight) * 1000) / 86400 ))
echo @$BTIME
However, you need to use an external program to calculate centibeats, since bash does not handle decimals well:
(using dc, which is a rpn calculator)
MIDNIGHT=$( TZ='Etc/GMT-1 date -d "12:00 am" +%s )
printf @
dc << EOF
# setting precision
2 k
# subtracting midnight from the current epoch
$EPOCHREALTIME $MIDNIGHT -
# converting to ms
1000 *
# divide by seconds in a day
86400 /
# print it to screen
p
EOF
To display it on your screen permanently, you can use any program that uses piped input, but lemonbar is the easiest to use:
while true
do
MIDNIGHT=$( TZ='Etc/GMT-1' date -d "12:00 am" +%s )
BTIME=$(( (($EPOCHSECONDS - $midnight) * 1000) / 86400 ))
echo @$BTIME
done | lemonbar -bg 48+0+18 # positions a little above the bottom left
(you can replace the code between the do and done with the dc version too)