Created
December 6, 2015 20:35
-
-
Save mmb/71a6e8a0a1ebb97c502e to your computer and use it in GitHub Desktop.
javascript current time in beats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1 id="time"></h1> | |
<script> | |
function toBeats(date) { | |
return ((date.getTime() / 1000.0) + 3600) % 86400 / 86.4; | |
} | |
function formatTime(date) { | |
return (date.getMonth() + 1) + "/" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes(); | |
} | |
function update() { | |
var d = new Date(); | |
document.getElementById("time").innerHTML = formatTime(d) + " / @" + Math.floor(toBeats(d)); | |
} | |
setInterval(update, 1000); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment