宇筱博客

  • 解决办法
  • 学无止境
  • 记录时光
  • 百宝箱
宇筱博客
点滴记忆,汇聚成海。
  1. 首页
  2. 解决办法
  3. 正文

js对日期加减指定天、时、分、秒

2020年1月1日 580点热度 0人点赞 0条评论

例如:当前日期为 2016-12-11 20:20:20

var t = new Date();//你已知的时间
var t_s = t.getTime();//转化为时间戳毫秒数
t.setTime(t_s + 1000 * 60);//设置新时间比旧时间多一分钟
alert(t) // 2016-12-11 20:21:20
t.setTime(t_s + 1000 * 60 * 60);//设置新时间比旧时间多一小时
alert(t) // 2016-12-11 21:20:20
t.setTime(t_s + 1000 * 60 * 60 * 24);//设置新时间比旧时间多一天
alert(t) // 2016-12-12 20:20:20

var t = new Date();//你已知的时间
t.setTime(t.setMinutes(t.getMinutes() + 1));//设置新时间比旧时间多一分钟
alert(t) // 2016-12-11 20:21:20
t.setTime(t.setHours(t.getHours() + 1));//设置新时间比旧时间多一小时
alert(t) // 2016-12-11 21:20:20

原文链接:https://blog.csdn.net/qq395537505/article/details/78753237

标签: 暂无
最后更新:2020年1月1日

小渔民

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2025 宇筱博客. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

豫ICP备15017825号-2