var Clock = waves('#template');
// Hook for when the view is created. This fires
// before the view is rendered
Clock.created(function () {
this.interval = setInterval(this.tick, 1000);
this.data.time = new Date();
this.data.minutes = new Array(60);
this.data.hours = new Array(12);
});
// Add interpolation filters
Clock.filter({
pad: function (num) {
return String(num < 10 ? '0' + num : num);
},
date: function (val) {
return val.getDate();
},
month: function (val) {
var month = val.getMonth();
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
return months[month];
},
day: function (val) {
var day = val.getDay();
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
return days[day];
}
});
// Every second this will get called and
// update the current time
Clock.prototype.tick = function () {
this.set('time', new Date());
};
// Create a new clock
var clock = new Clock();
// Append it
clock.appendTo('body');
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.