You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.8 KiB
JavaScript

2 years ago
document.write('<div style="position:absolute;width:4.2%;height:2%;top: 2.1%;left: 84.14%;border: 0 solid red;color:#71D7FF;font-size:0.08rem;">\n' +
' <span id="timeinfo"></span>\n' +
'</div>\n' +
'\n' +
'<div style="position:absolute;width:6%;height:2%;top: 2.1%;left: 92%;border: 0 solid red;color:#71D7FF;font-size:0.08rem;">\n' +
' <span id="dateinfo"></span>\n' +
'</div>\n')
/*alert($(window).height());
var sonStyle = document.getElementsByClassName("son");
sonStyle.style.height = $(window).height()-500 + "px";*/
let rootWidth = document.documentElement.clientWidth || document.body.clientWidth;
let rootDom = document.querySelector('html');
rootDom.style.fontSize = rootWidth / 10 + 'px';
getnow();
2 years ago
function getnow() {
2 years ago
//1、获得当前时间格式化时间
2 years ago
var now = new Date();
2 years ago
2 years ago
var year = now.getFullYear();
2 years ago
2 years ago
var month = now.getMonth() + 1;
2 years ago
2 years ago
if (month < 10) {
2 years ago
2 years ago
month = "0" + month;
2 years ago
}
2 years ago
var date = now.getDate();
2 years ago
2 years ago
if (date < 10) {
2 years ago
2 years ago
date = "0" + date;
2 years ago
}
2 years ago
var hour = now.getHours();
2 years ago
2 years ago
if (hour < 10) {
2 years ago
2 years ago
hour = "0" + hour;
2 years ago
}
2 years ago
var minute = now.getMinutes();
2 years ago
2 years ago
if (minute < 10) {
2 years ago
2 years ago
minute = "0" + minute;
2 years ago
}
2 years ago
var second = now.getSeconds();
2 years ago
2 years ago
if (second < 10) {
2 years ago
2 years ago
second = "0" + second;
2 years ago
}
2 years ago
var nowstr = year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
2 years ago
//alert(nowstr);
//alert(nowstr);
//2、显示时间 html
//获得标签对象
/*var nowspan=document.getElementById("nowspan");
nowspan.innerHTML=nowstr;*/
//2021-09-30 12:00:00
2 years ago
$("#dateinfo").html(nowstr.slice(0, 10));
$("#timeinfo").html(nowstr.slice(11, 19));
2 years ago
//3、使时间动起来
setTimeout("getnow()", 1000);
}