
vue聊天功能模块(十)音视频通话 时间、计时器
发布日期:2021-05-08 00:22:22
浏览次数:19
分类:精选文章
本文共 2763 字,大约阅读时间需要 9 分钟。
????????
???????????????Vue.js??????????????????????????????????
????
{{ currentTime }}
??????
getTime() { const now = new Date() const year = now.getFullYear() const month = now.getMonth() + 1 const day = now.getDate() const hour = now.getHours() const minutes = now.getMinutes() const seconds = now.getSeconds() // ???????? let clock = `${year}/${month}/${day} ` clock += `${hour}:${minutes}` return clock}
?????
????????????????????????????????
????
{{ msgIPtime.longTime }}
????????
???????????????????????????????????????
??????
setCurrentTime(date) { if (date === undefined) { return new Date() } const now = new Date(date) const year = now.getFullYear() const month = now.getMonth() + 1 const day = now.getDate() const hour = now.getHours() const minutes = now.getMinutes() const seconds = now.getSeconds() let clock = `${year}/${month}/${day} ` clock += `${hour}:${minutes}` return clock}
????
let currentTime = this.setCurrentTime(new Date())
???????
?????????????????????????????????????
???????
formatTime(time) { const date = new Date(time) const year = date.getFullYear() + '-' const month = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-' const day = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ' const hour = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':' const minutes = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':' const seconds = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()) return `${year}${month}${day}${hour}${minutes}${seconds}`}
????????
????????????????????????????????????????????
???????
calculateTimeDiff(dateBegin, dateEnd) { // ??????"2020-12-4 12:23:12"???????? Date ?? const dateBegin = new Date(dateBegin.replace(/-/g, '/')) const dateEnd = new Date(dateEnd.replace(/-/g, '/')) // ??????? const beginTime = dateBegin.getTime() const endTime = dateEnd.getTime() // ????? const diff = endTime - beginTime const dayDiff = Math.floor(diff / (24 * 3600 * 1000)) const remain = diff % (24 * 3600 * 1000) const hours = Math.floor(remain / (3600 * 1000)) const remainAfterHours = remain % (3600 * 1000) const minutes = Math.floor(remainAfterHours / (60 * 1000)) const remainAfterMinutes = remainAfterHours % (60 * 1000) const seconds = Math.round(remainAfterMinutes / 1000) return { dayDiff, hours, minutes, seconds }}
????
const result = this.calculateTimeDiff(dateBegin, dateEnd)console.log(result.dayDiff, result.hours, result.minutes, result.seconds)
??????????????????????????????????????????????????????????????????????????
发表评论
最新留言
感谢大佬
[***.8.128.20]2025年05月08日 04时44分23秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
LE33
2025-04-04
Leaflet 入门教程(一):应该如何学习 Leaflet
2025-04-04
Leaflet 入门教程(七):markers 篇
2025-04-04
Leaflet 入门教程(三):底图加载(18种)
2025-04-04
Leaflet 入门教程(二):Map 篇
2025-04-04
Leaflet 入门教程(八):交互事件篇
2025-04-04
Leaflet 入门教程(十二):定位与轨迹
2025-04-04
Leaflet 入门教程(十四):数据转换
2025-04-04
Leaflet 入门教程(四):文件加载( 10多种文件格式)
2025-04-04
leaflet 综合教程150+ 【目录 】
2025-04-04
leaflet+turf截取线上线段(leaflet篇.36)
2025-04-04
leaflet+turf获取geojson面的中心点与质心(leaflet篇.63)
2025-04-04
Leaflet中使用awesome-markers插件显示带图标的marker
2025-04-04
Leaflet中使用draw绘制时获取图形的几何信息
2025-04-04