vue聊天功能模块(十)音视频通话 时间、计时器
发布日期:2021-05-08 00:22:22 浏览次数:19 分类:精选文章

本文共 2763 字,大约阅读时间需要 9 分钟。

????????

???????????????Vue.js??????????????????????????????????

????

??????

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}

?????

????????????????????????????????

????

????????

???????????????????????????????????????

??????

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)

??????????????????????????????????????????????????????????????????????????

上一篇:Sortable排序在vue使用/使用element弹框拖拽排序
下一篇:vue聊天功能模块(四)聊天消息换行

发表评论

最新留言

感谢大佬
[***.8.128.20]2025年05月08日 04时44分23秒