CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: JavaScript

Javascript clock

192 Views
Copy Code Show/Hide Line Numbers
// Iphone Javascript Clock
var timerID = null;
var timerRunning = false;
function stopclock() {
    if (timerRunning)
        clearTimeout(timerID);
    timerRunning = false;
}
function showtime() {
    var timeValue;
    now = new Date();
    clockHour = now.getHours();
    clockMinute = now.getMinutes();
    clockSecond = now.getSeconds();
    if (clockHour < 12) { ampm = "AM" } else { ampm = "PM"; clockHour = clockHour - 12; }
    if (clockHour < 10) { clockHour = "0" + clockHour; }
    if (clockHour == 0) { clockHour = "12"; }
    if (clockMinute < 10) { clockMinute = "0" + clockMinute; }
    timeValue = clockHour + ":" + clockMinute + " " + ampm; 
    $('#Clock').html(timeValue)
    timerID = setTimeout("showtime()", 10000);
    timerRunning = true;
}
function startclock() {
    stopclock();
    showtime();
}
by Arjan
  May 18, 2010 @ 5:40am
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate