Skip to content

Instantly share code, notes, and snippets.

@mbostock
Last active February 9, 2016 01:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbostock/9843633 to your computer and use it in GitHub Desktop.
Save mbostock/9843633 to your computer and use it in GitHub Desktop.
Countdown
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
<style>
#countdown {
font: 100px/500px Menlo;
text-align: center;
width: 960px;
}
</style>
<div id="countdown"></div>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
var formatTime = d3.time.format("T-%X"),
countdown = d3.select("#countdown"),
today = d3.time.day(new Date);
// 9 AM tomorrow
var deadline = d3.time.day.offset(today, 1);
deadline.setHours(9);
(function tick() {
var now = new Date;
countdown.text(formatTime(new Date(+today + +deadline - d3.time.second(now))));
setTimeout(tick, 1000 - now % 1000);
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment