中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
微信扫码分享
@Entry @Component struct Arc { @State countdownValue: string = '1'; aboutToAppear(): void { } build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Text(this.countdownValue).backgroundColor(Color.Blue).fontColor(Color.White).width(300).height(45) .textAlign(TextAlign.Center) } .width('100%') .height('100%') } onPageShow(): void { setInterval(()=>{ let target = 1730339780000 let result = new Date().getTime() let dd = target - result let days=Math.floor(dd/(24*3600*1000)) let leave1=dd%(24*3600*1000) //计算天数后剩余的毫秒数 let hours=Math.floor(leave1/(3600*1000)) //计算相差分钟数 let leave2=leave1%(3600*1000) //计算小时数后剩余的毫秒数 let minutes=Math.floor(leave2/(60*1000)) //计算相差秒数 let leave3=leave2%(60*1000) //计算分钟数后剩余的毫秒数 let seconds=Math.round(leave3/1000) console.log('距离结束'+days+'天'+hours+':'+minutes+':'+seconds) this.countdownValue = '距离结束'+days+'天'+hours+':'+minutes+':'+seconds; }, 1000); } }