当前位置:网站首页>[JS component] date display.
[JS component] date display.
2022-07-07 05:24:00 【KatyLight】

The date of the component , It will change over time . Implementation code :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body{
background-color: black;
color: white;
}
.KatyLightTimeBox{
color: #00ff95;
font-size: 2rem;
font-weight: bolder;
}
.KatyLightTimeBox>.time{
margin-left: 1rem;
}
</style>
<script>
class KatyLightTimeBox{
constructor(params) {
this.target=params.target;
let date=new Date();
let year=date.getFullYear();
let mouth=date.getMonth()+1;
let d=date.getDate();
let h=date.getHours();
let m=date.getMinutes();
let s=date.getSeconds();
this.timeSpan=this.target.querySelector('.time')
this.dateSpan=this.target.querySelector('.date')
this.data=[
year,mouth,d,h,m,s
]
this.dateSpan.innerText=this.dateFormat();
this.run()
}
run(){
setInterval(()=>{
let cc=false;
this.data[5]++;
if(this.data[5]>=60){
this.data[5]=0;
this.data[4]++
}
if(this.data[4]>=60){
this.data[4]=0;
this.data[3]++
}
if(this.data[3]>=24){
this.data[3]=0;
this.data[2]++
cc=true;
}
this.timeSpan.innerText=this.timeFormat();
if(!cc){
return;
}
let max=30;
if(this.data[1]<8){
if(this.data[1]%2===0){
if(this.data[1]===2){
if(this.data[0]%400===0||(this.data[0]%4===0&&this.data[0]%100!==0)){
max=29
}else{
max=28
}
}else{
max=30
}
}else{
max=31
}
}else{
if(this.data[1]%2===0){
max=31
}else{
max=30
}
}
if(this.data[2]>max){
this.data[2]=0;
this.data[1]++;
}
if(this.data[1]>12){
this.data[1]=1;
this.data[0]++;
}
this.dateSpan.innerText=this.dateFormat();
},1000)
}
dateFormat(){
let s=this.data[0].toString();
let m=this.data[1].toString();
if(m.length<2){
m="0"+m;
}
let h=this.data[2].toString();
if(h.length<2){
h="0"+h;
}
return h+"."+m+"."+s
}
timeFormat(){
let s=this.data[5].toString();
if(s.length<2){
s="0"+s;
}
let m=this.data[4].toString();
if(m.length<2){
m="0"+m;
}
let h=this.data[3].toString();
if(h.length<2){
h="0"+h;
}
return h+":"+m+":"+s
}
}
window.onload=()=>{
new KatyLightTimeBox({
target:document.querySelector('.KatyLightTimeBox')
})
}
</script>
</head>
<body>
<div class="KatyLightTimeBox"><span class="date">2012.12.21</span><span class="time">12:00:00</span></div>
</body>
</html>
边栏推荐
- 漏电继电器JOLX-GS62零序孔径Φ100
- Full link voltage test: the dispute between shadow database and shadow table
- Wonderful express | Tencent cloud database June issue
- 2039: [蓝桥杯2022初赛] 李白打酒加强版 (动态规划)
- pmp真的有用吗?
- AOSP ~binder communication principle (I) - Overview
- CentOS 7.9 installing Oracle 21C Adventures
- DBSync新增对MongoDB、ES的支持
- If you‘re running pod install manually, make sure flutter pub get is executed first.
- 利用OPNET进行网络仿真时网络层协议(以QoS为例)的使用、配置及注意点
猜你喜欢

Is the human body sensor easy to use? How to use it? Which do you buy between aqara green rice and Xiaomi

Record a pressure measurement experience summary

EGR-20USCM接地故障继电器

Autowired注解用于List时的现象解析

Pytest testing framework -- data driven

【js组件】date日期显示。

Error: No named parameter with the name ‘foregroundColor‘

【问道】编译原理

JVM(二十) -- 性能监控与调优(一) -- 概述

The sooner you understand the four rules of life, the more blessed you will be
随机推荐
Writing process of the first paper
Mysql database learning (7) -- a brief introduction to pymysql
Dbsync adds support for mongodb and ES
Salesforce 容器化 ISV 场景下的软件供应链安全落地实践
app clear data源码追踪
window定时计划任务
实现网页内容可编辑
做自媒体,有哪些免费下载视频剪辑素材的网站?
【js组件】自定义select
Scheduledexecutorservice timer
人体传感器好不好用?怎么用?Aqara绿米、小米之间到底买哪个
高压漏电继电器BLD-20
ASP. Net MVC - resource cannot be found error - asp Net MVC – Resource Cannot be found error
Simulate thread communication
基于 hugging face 预训练模型的实体识别智能标注方案:生成doccano要求json格式
Knapsack problem (01 knapsack, complete knapsack, dynamic programming)
漏电继电器JELR-250FG
Redis如何实现多可用区?
利用OPNET进行网络仿真时网络层协议(以QoS为例)的使用、配置及注意点
NPDP产品经理认证,到底是何方神圣?