Hello,
I’m trying to create a clock that updates in real-time.
So far I only had a clock that only update upon a refresh, however I started to rewrite it using ReactiveVars, without success.
can anyone help me?
UPDATE: GOT IT WORKING!
My html
<div id="container">
<div id="info">
<div id="time">
<span id="hours">{{clock_hour}}</span>:<span id="minutes">{{clock_minute}}</span>:<span id="seconds">{{clock_second}}</span>
</div>
</div>
</div>
</li>
My helper
clock_hour: function(){
return Session.get('hour');
},
clock_minute: function(){
return Session.get('minute');
},
clock_second: function(){
return Session.get('second');
},
Reactive var (should update every second)
function getSecond(){
var d = new Date();
return d.getSeconds();
};
function getMinute(){
var d = new Date();
return d.getMinutes();
};
function getHour(){
var d = new Date();
return d.getHours();
};
Meteor.setInterval(function() {
Session.set('second', getSecond());
Session.set('minute', getMinute());
Session.set('hour', getHour());
}, 1000);