小程序计算到计时的时分秒,小程序计算时间差
var timestamp = Date.parse(new Date()); var totime = 过期的时间秒; //当前时间撮 timestamp = timestamp / 1000; var surplus = totime - timestamp; if ( surplus < 0 ) { var maxtime = surplus; var second = Math.floor(maxtime % 60); //计算秒 var minite = Math.floor((maxtime / 60) % 60); //计算分 var hour = Math.floor((maxtime / 3600) % 24); //计算小时 var day = Math.floor((maxtime / 3600) / 24); //计算相差秒数 console.log(day + '天' + hour + "小时 " + minite + " 分钟" + second + '秒'); }
本文由:xiaoshu168 作者:xiaoshu发表,转载请注明来源!