JS获取当前时间的年、月、日、时间
function showtime() {
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var day = date.getDate();
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
console.log(`${day}`)
if (day == 0) {
day == '日';
}
if (seconds < 10) {
seconds = "0" + seconds;
}
if (minutes < 10) {
minutes = "0" + minutes;
}
if (hours < 10) {
hours = "0" + hours;
}
var time = year + "/" + month + "/" + day + " " + hours + ":" + minutes + ":" + seconds;
var o = document.getElementById("box");
o.innerHTML = time;
console.log(time, '.....')
setTimeout(showtime, 1000)
}
showtime();