https://github.com/taylorhakes/clock-interval
A precise interval timer
https://github.com/taylorhakes/clock-interval
Last synced: 30 days ago
JSON representation
A precise interval timer
- Host: GitHub
- URL: https://github.com/taylorhakes/clock-interval
- Owner: taylorhakes
- License: mit
- Created: 2015-08-02T19:01:29.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-08-04T04:04:20.000Z (about 10 years ago)
- Last Synced: 2025-08-27T13:47:40.712Z (about 1 month ago)
- Language: JavaScript
- Size: 129 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# clock-interval
A precise interval timer pinned to system clock## How to use
```
npm install clock-interval
```#### Example usage
Update an element with the currnt time
```js
var clockInterval = require('clock-interval');function pad(num) {
return ('0' + num).slice(-2);
}
clockInterval(function() {
var clockEl = document.getElementById('clock'),
dateObj = new Date();
clockEl.innerHTML = pad(dateObj.getHours()) + ':' + pad(dateObj.getMinutes()) + ':' + pad(dateObj.getSeconds());
});
```Cancel the interval
```js
var timer = clockInterval(function() {});// Cancel the timer
timer.cancel();
```## Why not use setInterval?
Check the link for more info [https://taylorhakes.com/2015/08/03/clock-setinterval/](https://taylorhakes.com/2015/08/03/clock-setinterval/)