Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
javascript current time in beats
<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