﻿var timerID = null;
var timerRunning = false;
function stopclock ()
{
    if(timerRunning)
    clearTimeout(timerID);
    timerRunning = false;
}
function showtime () {
d = new Date();
dateText = "";
dayValue = d.getDay();
if(dayValue == 0)
    dateText += "Chủ nhật";
else if (dayValue == 1)
    dateText += "Thứ hai";
else if (dayValue == 2)
    dateText += "Thứ ba";
else if (dayValue == 3)
    dateText += "Thứ tư";
else if (dayValue == 4)
    dateText += "Thứ năm";
else if (dayValue == 5)
    dateText += "Thứ sáu";
else if (dayValue == 6)
    dateText += "Thứ bảy";
// Get the current date; if it's before 2000,add 1900
dateText += ", Ngày " + d.getDate();
// lấy tháng hiện tại và chuyển nó sang tháng theo tiếng Việt Nam
monthValue = d.getMonth();
dateText += "";
if (monthValue == 0)
    dateText += "/1";
if (monthValue == 1)
    dateText += "/2";
if (monthValue == 2)
    dateText += "/3";
if (monthValue == 3)
    dateText += "/4";
if (monthValue == 4)
    dateText += "/5";
if (monthValue == 5)
    dateText += "/6";
if (monthValue == 6)
    dateText += "/7";
if (monthValue == 7)
    dateText += "/8";
if (monthValue == 8)
    dateText += "/9";
if (monthValue == 9)
    dateText += "/10";
if (monthValue == 10)
    dateText += "/11";
if (monthValue == 11)
    dateText += "/12";
    
// Get the current year; if it's before 2000, add 1900
if (d.getYear() < 2000)
    dateText += "/" + (1900 + d.getYear());
else
    dateText += "/" + (d.getYear());

var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "" + ((hours >12) ? hours -12 :hours)
if (timeValue == "0") timeValue = 12;
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " PM" : " AM"

objtime = document.getElementById("timmer");
objtime.innerHTML = dateText + "";

timerID = setTimeout("showtime()",1000);
timerRunning = true;
}

function startclock() {
stopclock();
showtime();
}


