Date 日期和时间

2019-10-08  本文已影响0人  楼水流云

new Date() 获取当前时间
date .getTime() 获取当前时间毫秒数 (同set)
.getFullYear() 返回年份 (同set)
.getDate() 返回每个月的几号 (同set)
.getDay() 返回星期 周几 星期几 (同set)
.getMinth() 返回月份 从0开始计算 0就是1月份 (同set)
.getHours() 返回小时数 (同set)
.getMilliseconde() 返回毫秒数 (同set)
.getMinutes() 返回分 (同set)
.getSeconds() 返回秒 (同set)
.getTimezoneOffset() 返回当前时区与UTC时区差异,以分钟表示,考虑到了夏令时因素 (同set)
.now()获得一个当前距离 1970年1月1日00:00:00的毫秒数
.parse() 输入一个时间 用-分隔 2017-08-10 获得一个时间对象
.UTC() utc世界标准时间
.toString() 把当前时间转换成字符串

获取目标时间 离现在有多长时间
function getChintv(dateStr) {
var targetDate = new Date(dateStr)
var curDate = new Date()
var offset = Math.abs(targetDate - curDate)
var totalSeconds = Math.floor(offset/1000)

var second = totalSeconds%60
var totaLminntes = Math.floor((offset/1000)/60)
var minutes = totaLminntes%60
var totalHours = Math.floor(totaLminntes/60)
var hours = totalHours%24
var totalDays = Math.floor(totalHours/24)

return totalDays + "天" + hours + "小时" + minutes + "分钟" + second + "秒"

}

上一篇下一篇

猜你喜欢

热点阅读