网站代码结构,成都住建局官网报名入口,高密做网站哪家好价位,网络营销推广方案思路日期对象
实例化
代码中出现new关键字#xff0c;创建时间对象
得到当前时间#xff1a;
const date new Date#xff08;#xff09;
获得指定时间#xff1a;
const date new Date#xff08;‘2022-5-1’#xff09;
方法作用说明getFullYear()获取年份获取…日期对象
实例化
代码中出现new关键字创建时间对象
得到当前时间
const date new Date
获得指定时间
const date new Date‘2022-5-1’
方法作用说明getFullYear()获取年份获取四位年份getmonth()获取月份取值0~11getDate()获取月份中的每一天不同月份取值不同getDay()获取星期取值0~6getHours()获取小时取值0~23getMinutes()获取分钟取值0~59getSeconds()获取秒取值0~59 应用定时器可以实时显示时间
toLocaleString()、toLocaleDateString()、toLocaleTimeString()也可以显示粗略时间 时间戳
使用场景倒计时效果 什么是时间戳
1970年01月1日0时0分0秒其到现在毫秒数计量时间的方式 算法
将来的时间戳-现在的时间戳剩余时间戳 三种方法
1.getTime() 2.new Date()
获得指定时间戳 3.Date.now() 对于返回星期有些特殊 倒计时案例
!DOCTYPE html
html langenheadmeta charsetUTF-8meta http-equivX-UA-Compatible contentIEedgemeta nameviewportcontentwidthdevice-width, initial-scale1.0, maximum-scale1.0, minimum-scale1.0, user-scalablenotitle~/titlelink relshortcut icon hrefhttps://www.bilibili.com/favicon.icolink relstylesheet hrefcss/初始化表.csslink relstylesheet hrefcss/index.cssmeta namekeywords content... /style/*写代码时始终要考虑权重问题*/font-face {font-family: icomoon;src: url(fonts/icomoon.eot?au9n7q);src: url(fonts/icomoon.eot?au9n7q#iefix) format(embedded-opentype),url(fonts/icomoon.ttf?au9n7q) format(truetype),url(fonts/icomoon.woff?au9n7q) format(woff),url(fonts/icomoon.svg?au9n7q#icomoon) format(svg);font-weight: normal;font-style: normal;font-display: block;}.countdown {width: 240px;height: 305px;text-align: center;color: #fff;background-color: brown;line-height: 1;overflow: hidden;}.countdown .next {font-size: 16px;margin: 25px 0 14px;}.countdown .title {font-size: 33px;}.countdown .clock {width: 142px;margin: 18px auto 0;overflow: hidden;}.countdown .clock span,.countdown .clock i {display: block;text-align: center;line-height: 34px;font-size: 23px;float: left;}.countdown .clock span {width: 34px;height: 34px;border-radius: 2px;background-color: #303430;}.countdown .tips {margin-top: 80px;font-size: 23px;}.countdown .clock i {width: 20px;font-style: normal;}/style
/headbodydiv classcountdownp classnext/pp classtitle下班倒计时/pp classclockspan classhour/spani:/ispan classminutes/spani:/ispan classscond/span/pp classtips18:30:00 下课/p/divscriptlet date new Date()const next document.querySelector(.next)next.innerHTMLdate.toLocaleDateString()function fn() {let now new Date()let last new Date(2024-2-29 18:30:00)const count (last - now) / 1000let h parseInt(count / 3600 % 24)h h 10 ? h : 0 hlet m parseInt(count / 60 % 60)m m 10 ? m : 0 mlet s parseInt(count % 60)s s 10 ? s : 0 sconst hour document.querySelector(.hour)const minutes document.querySelector(.minutes)const scond document.querySelector(.scond)hour.innerHTML hminutes.innerHTML mscond.innerHTML s}fn() setInterval(fn, 1000)/script/body/html