当前位置:网站首页>[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>
边栏推荐
- Leetcode (417) -- Pacific Atlantic current problem
- Most commonly used high number formula
- 2039: [蓝桥杯2022初赛] 李白打酒加强版 (动态规划)
- HarmonyOS第四次培训
- 【opencv】图像形态学操作-opencv标记不同连通域的位置
- Is the human body sensor easy to use? How to use it? Which do you buy between aqara green rice and Xiaomi
- DBSync新增对MongoDB、ES的支持
- torch optimizer小解析
- NPDP产品经理认证,到底是何方神圣?
- How does redis implement multiple zones?
猜你喜欢

A cool "ghost" console tool

利用OPNET进行网络单播(一服务器多客户端)仿真的设计、配置及注意点

照片选择器CollectionView

漏电继电器JOLX-GS62零序孔径Φ100

If you‘re running pod install manually, make sure flutter pub get is executed first.

SQL injection - secondary injection and multi statement injection

torch optimizer小解析

Window scheduled tasks

y58.第三章 Kubernetes从入门到精通 -- 持续集成与部署(三一)

DOM-节点对象+时间节点 综合案例
随机推荐
【js组件】自定义select
Leetcode(417)——太平洋大西洋水流问题
背包问题(01背包,完全背包,动态规划)
利用OPNET进行网络任意源组播(ASM)仿真的设计、配置及注意点
Mysql database learning (8) -- MySQL content supplement
阿里云的神龙架构是怎么工作的 | 科普图解
QSlider of QT control style series (I)
说一说MVCC多版本并发控制器?
HarmonyOS第四次培训
The founder has a debt of 1billion. Let's start the class. Is it about to "end the class"?
Leetcode(46)——全排列
Longest non descent subsequence (LIS) (dynamic programming)
Redis如何实现多可用区?
Is PMP really useful?
一条 update 语句的生命经历
ThinkPHP Association preload with
ThinkPHP关联预载入with
做自媒体,有哪些免费下载视频剪辑素材的网站?
最长不下降子序列(LIS)(动态规划)
SQL injection cookie injection