JS 日期时间没有 [=10th=] 任何东西
JS Date&Time doesn't return anything
我创建了一个 javascript 来在 Javascript 中显示日期和时间,但它没有 return 任何东西
我尝试了很多建议,但没有任何效果。
HTML 代码
function startTime() {
var today = new Date();
var hr = today.getHours();
var min = today.getMinutes();
var sec = today.getSeconds();
ap = (hr < 12) ? "<span>AM</span>" : "<span>PM</span>";
hr = (hr == 0) ? 12 : hr;
hr = (hr > 12) ? hr - 12 : hr;
//Add a zero in front of numbers<10
hr = checkTime(hr);
min = checkTime(min);
sec = checkTime(sec);
document.getElementById("clock").innerHTML = hr + ":" + min + ":" + sec + " " + ap;
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
var curWeekDay = days[today.getDay()];
var curDay = today.getDate();
var curMonth = months[today.getMonth()];
var curYear = today.getFullYear();
var date = curWeekDay+", "+curDay+" "+curMonth+" "+curYear;
document.getElementById("date").innerHTML = date;
var time = setTimeout(function(){ startTime() }, 500);
}
function checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
div {
margin
border-radius:15px;
color:#ecf0f1;
text-align:center;
font-size:70px
}
<div id="clock"></div>
<div id="date"></div>
我可以更改此 javascript 代码以显示 5 个不同时区的时间吗?
为了使其正常工作,调用函数 startTime 很重要,因此请将此行添加到您的 javasrcipt 代码中。
startTime();
啊,忘记打电话了。对不起。
曾与
合作
window.onload = function () {
'use strict';
setInterval(startTime, 500);
我创建了一个 javascript 来在 Javascript 中显示日期和时间,但它没有 return 任何东西 我尝试了很多建议,但没有任何效果。
HTML 代码
function startTime() {
var today = new Date();
var hr = today.getHours();
var min = today.getMinutes();
var sec = today.getSeconds();
ap = (hr < 12) ? "<span>AM</span>" : "<span>PM</span>";
hr = (hr == 0) ? 12 : hr;
hr = (hr > 12) ? hr - 12 : hr;
//Add a zero in front of numbers<10
hr = checkTime(hr);
min = checkTime(min);
sec = checkTime(sec);
document.getElementById("clock").innerHTML = hr + ":" + min + ":" + sec + " " + ap;
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
var curWeekDay = days[today.getDay()];
var curDay = today.getDate();
var curMonth = months[today.getMonth()];
var curYear = today.getFullYear();
var date = curWeekDay+", "+curDay+" "+curMonth+" "+curYear;
document.getElementById("date").innerHTML = date;
var time = setTimeout(function(){ startTime() }, 500);
}
function checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
div {
margin
border-radius:15px;
color:#ecf0f1;
text-align:center;
font-size:70px
}
<div id="clock"></div>
<div id="date"></div>
我可以更改此 javascript 代码以显示 5 个不同时区的时间吗?
为了使其正常工作,调用函数 startTime 很重要,因此请将此行添加到您的 javasrcipt 代码中。
startTime();
啊,忘记打电话了。对不起。
曾与
合作window.onload = function () {
'use strict';
setInterval(startTime, 500);