﻿var timerID = null;
var timerRunning = false;
Date.prototype.toString = function (showWeek) {
    var myDate = this;
    var str = myDate.toLocaleDateString();
    if (showWeek) {
        var Week = ['日', '一', '二', '三', '四', '五', '六'];
        str += ' 星期' + Week[myDate.getDay()];
    }
    return str;
}
function startclock() {
    // 确认时钟已经停止。
    stopclock();
    // 显示出时钟。
    showtime();
}
function stopclock() {
    if (timerRunning) {
        clearTimeout(timerID);
        timerRunning = false;
    }
}
function showtime() {
    var now = new Date();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    var seconds = now.getSeconds();
    var timeValue = " " + hours;
    timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
    timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
    //timeValue += (hours >= 12) ? " 下午" : " 上午";
    document.getElementById("lblDate").innerText = new Date().toString(true) + " " + timeValue;
    timerID = setTimeout("showtime()", 1000);
    timerRunning = true;
}

