当前位置:网站首页>Page dynamic display time (upgraded version)
Page dynamic display time (upgraded version)
2022-04-23 07:45:00 【Senior salted fish~】
Realize button control time display
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Page dynamic display time </title>
</head>
<body>
<div>
<p class="p1"></p>
<button class="btn"> Stop time </button>
</div>
<script>
// Format :2020 year 04 month 12 Japan 10:20:00 Tuesday
var p1 = document.querySelector(".p1")
var btn = document.querySelector(".btn")
var timerId = setInterval(format, 1000)
var flag = true
function format() {
var newDate = new Date()
var day = newDate.getDay()
var y = newDate.getFullYear()
var m = (newDate.getMonth() + 1) < 10 ? "0" + (newDate.getMonth() + 1) : (newDate.getMonth() + 1)
var d = newDate.getDate() < 10 ? "0" + newDate.getDate() : newDate.getDate()
var h = newDate.getHours() < 10 ? "0" + newDate.getHours() : newDate.getHours()
var min = newDate.getMinutes() < 10 ? "0" + newDate.getMinutes() : newDate.getMinutes()
var s = newDate.getSeconds() < 10 ? "0" + newDate.getSeconds() : newDate.getSeconds()
var dict = {
1: " One ",
2: " Two ",
3: " 3、 ... and ",
4: " Four ",
5: " 5、 ... and ",
6: " 6、 ... and ",
0: " God ",
}
//var week=[" Japan "," One "," Two "," 3、 ... and "," Four "," 5、 ... and "," 6、 ... and "]
var matDate = y + " year " + m + " month " + d + " Japan " + h + ":" + min + ":" + s + " week " + dict[day]
p1.textContent = matDate
}
btn.onclick = function () {
if (flag) {
// Stop time
clearInterval(timerId)
btn.textContent = " Starting time "
timerId = null
flag = false
} else {
btn.textContent = " Stop time "
timerId = setInterval(format, 1000)
flag = true
}
}
</script>
</body>
</html>
Effect display :
版权声明
本文为[Senior salted fish~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230623086896.html
边栏推荐
- 8. Paging query
- FSM有限状态机
- Mobile game performance optimization
- 4. Multi table query
- Reflect on the limitations of event bus and the design and implementation of communication mechanism in component development process
- js之函数的两种声明方式
- Judge whether the beginning and end of the string contain target parameters: startswith() and endswith() methods
- 2022.3.14 Ali written examination
- King glory - unity learning journey
- js之自定义属性以及H5中如何判断自定义属性
猜你喜欢
页面动态显示时间(升级版)
ogldev-读书笔记
AuthorizationServer(授权服务器的简单搭建)
Install and configure Taobao image NPM (cnpm)
页面实时显示当前时间
SAP ECC连接SAP PI系统配置
FSM finite state machine
Authorization+Token+JWT
Mysql 索引
Reflect on the limitations of event bus and the design and implementation of communication mechanism in component development process
随机推荐
js之什么是事件?事件三要素以及操作元素
面经的总结
Mvcc (multi version concurrency control)
Nacos / sentinel gateway current limiting and grouping (code)
反思 | Android 音视频缓存机制的系统性设计
14. Transaction processing
FSM finite state machine
AuthorizationServer(授权服务器的简单搭建)
new的实现
反思 | 事件总线的局限性,组件化开发流程中通信机制的设计与实现
移动Web(字体图标、平面转换、颜色渐变)
js之自定义属性以及H5中如何判断自定义属性
keytool: command not found
系统与软件安全研究(二)
c#读取INI文件和向ini文件写入数据
js之DOM事件
4.多表查询
promise all的实现
What are the total number of all courses of Mr. Tang Xiaoyang, who is very popular in CSDN (question mark)
Date对象(js内置对象)