商城秒杀倒计时函数封装
function hoursToMilliseconds(hours) {
const millisecondsInAnHour = 60 * 60 * 1000;
const milliseconds = hours * millisecondsInAnHour;
return milliseconds;
}
function daysToMilliseconds(days) {
const millisecondsInADay = 24 * 60 * 60 * 1000;
const milliseconds = days * millisecondsInADay;
return milliseconds;
}
function millisecondsToHours(milliseconds) {
const seconds = milliseconds / 1000;
const minutes = seconds / 60;
const hours = minutes / 60;
return hours;
}
function millisecondsToDays(milliseconds) {
const seconds = milliseconds / 1000;
const minutes = seconds / 60;
const hours = minutes / 60;
const days = hours / 24;
return days;
}
function hourEndTime(hour){
let dataNow = Date.now();
let hourToMill = this.hoursToMilliseconds(hour);
return dataNow + hourToMill;
}
function dayEndTime(day){
let dataNow = Date.now();
let dayToMill = this.daysToMilliseconds(day);
return dataNow + dayToMill;
}
function hourRemainTime(allData){
let dataNow = Date.now();
return allData - dataNow
}
module.exports = {
hoursToMilliseconds,
daysToMilliseconds,
millisecondsToHours,
millisecondsToDays,
hourEndTime,
dayEndTime,
hourRemainTime,
}