simple-clock.js
1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(function($)
{
$.fn.simpleClock = function()
{
function getTime()
{
var date = new Date(),
hour = date.getHours();
return {
day: $L.days[calculateDay(date.getDay())],
date: date.getDate(),
month: $L.months[date.getMonth()],
hour: appendZero(hour),
minute: appendZero(date.getMinutes()),
second: appendZero(date.getSeconds())
};
}
// tage umrechen, da in der Languages der wochentag mit Montag beginnt und nicht mit Sonntag wie in JS benötigt
function calculateDay(weekday)
{
if(weekday == 0){
return 6;
}
return weekday - 1;
}
// appendZero - If the number is less than 10, add a leading zero.
function appendZero(num)
{
if (num < 10) {
return "0" + num;
}
return num;
}
// refreshTime - Build the clock.
function refreshTime()
{
var now = getTime();
//$('#date-container').html(now.day + ' ' + now.date + '. ' + now.month);
$('#date-container-day').html(now.day);
$('#date-container-date').html(now.date);
$('#date-container-month').html(now.month);
$('#time-container').html("<span class='time-hour'>" + now.hour + "</span>" + ":<span class='time-minute'>" + now.minute + "</span>");
}
// Tick tock - Run the clock.
refreshTime();
setInterval(refreshTime, 1000);
};
})(jQuery);