var date=new Date(); //1. js获取当前时间
var min=date.getMinutes(); //2. 获取当前分钟
date.setMinutes(min+10); //3. 设置当前时间+10分钟:把当前分钟数+10后的值重新设置为date对象的分钟数
var y = date.getFullYear();
var m = (date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : (date.getMonth() + 1);
var d = date.getDate() < 10 ? ("0" + date.getDate()) : date.getDate();
var h = date.getHours() < 10 ? ('0' + date.getHours()) : date.getHours()
var f = date.getMinutes() < 10 ? ('0' + date.getMinutes()) : date.getMinutes()
var s = date.getSeconds() < 10 ? ('0' + date.getseconds()) : date.getSeconds()
var formatdate = y+'-'+m+'-'+d + " " + h + ":" + f + ":" + s;
console.log(formatdate) // 获取10分钟后的时间,格式为yyyy-mm-dd h:f:s
js获取n分钟后(或前)的时间
最新推荐文章于 2022-11-08 17:10:47 发布