我的数字时钟不会从AM变为PM

时间:2017-02-24 17:05:28

标签: clock

我正在努力让我的数字时钟从AM变为PM。但它只会留在AM上,即使它应该在PM上。它需要与计算机上设置的时间相同。关心帮忙?谢谢大家,这是我的代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Current Time</title>

<style>
.mytime {font-size: 150px;
         margin: 0 auto;
         padding: 10px;
         color: #ffffff;
         font-weight: bold;
         text-align: center;
        }

.myTxt {font-size: 72px;
         margin: 0 auto;
         padding: 10px;
         color: #ffffff;
         font-weight: bold;
         text-align: center;
        }
</style>
</head>

<body style="background-color: #000;">

<div ID="TimeBlock" class="mytime"></div>

<div ID="Content" class="myTxt"><small>Brought to you by</small> <br>Nate
        <br /><br /><br />
        A Simulated Workplace Environment 

`enter code here`</div>

    <script type="text/javascript" langauage="javascr

ipt">
function renderTime() {
    var currentTime = new Date();
    var diem = "AM";
    var h = currentTime.getHours();
    var m = currentTime.getMinutes();
    var s = currentTime.getSeconds();

    if (h == 0) {
        h = 12;
        } 
        else if (h > 12) {
        h = h - 12
        diem = "PM";
        }
            if (h < 10) {
            h = "0" + h 
            }
            if (m < 10) {
            m = "0" + m 
            }
            if (s < 10) {
            s = "0" + s 
            }
    var myDisplayTime = document.getElementById("TimeBlock");
    myDisplayTime.textContent = h + ":" + m + ":" + s + " " + diem;
    myDisplayTime.innerText = h + ":" + m + ":" + s + " " + diem;
    setTimeout('renderTime()', 1000);
    }
renderTime();

</script>


<script>
alert("Open this?")
</script>



</body>

0 个答案:

没有答案