Skip to content

Instantly share code, notes, and snippets.

@yakirh
Created October 13, 2013 13:38
Show Gist options
  • Select an option

  • Save yakirh/6962474 to your computer and use it in GitHub Desktop.

Select an option

Save yakirh/6962474 to your computer and use it in GitHub Desktop.
JS Timer exercise
<!DOCTYPE html>
<html>
<head>
<title>Timer</title>
</head>
<body>
<h2>Current Time: </h2>
<div id="time"></div>
<script type="text/javascript">
var now;
function display_time() {
now = new Date;
document.getElementById('time').innerHTML =
('0' + now.getHours()).slice(-2)
+':'+
('0' + now.getMinutes()).slice(-2)
+':'+
('0' + now.getSeconds()).slice(-2);
}
display_time();
setInterval(display_time, 1000);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment