Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const timer = {
- time: 0,
- timeStart: 0,
- timeEnd: 0,
- interval: 50,
- init: function() {
- this.timeStart = new Date();
- },
- setTimeStart: function() {
- if (this.timeStart == 0) {
- this.timeStart = Math.floor(Date.now() / 1000);
- }
- },
- start: function() {
- this.setTimeStart();
- var now = Math.floor(Date.now() / 1000); // get the time now
- var diff = now - this.timeStart; // diff in seconds between now and start
- // console.log('now', now);
- // console.log('timestart', this.timeStart);
- console.log('diff', diff);
- this.sync(diff);
- setTimeout(this.start(), this.interval * 1000); // set a timeout to update the timer
- },
- stop: function() {
- clearTimeout(this.start());
- },
- sync: function(time) {
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement