JS 时间戳 加减 几个小时 方法
文章目录
话不多说直接看代码
// 获取当前时间方式
// 精确到 毫秒时间戳:
new Date(new Date().setHours(new Date().getHours() + 8)).valueOf()
// 精确到 毫秒时间戳:
new Date(new Date().setHours(new Date().getHours() + 8)).getTime()
// 精确到秒:
Date.parse(new Date(new Date().setHours(new Date().getHours() + 8)))
// 传入一个时间戳方式
var curTime = new Date(parseInt(1653609147000))
curTime.setHours(curTime.getHours() + 8)
// 在附带一个小技巧 可以快速将时间戳转换 日期格式
new Date(parseInt(1653609147000))
new Date(parseInt(1653609147000)).toLocaleString()
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论