✨ 根据传入的小时分钟,返回其对应的时间戳(ms)
- ⌛ 使用场景:当展示所需数据格式与接口的数据格式不同时,更方便的去转换格式。
- ⏳ 入参: 小时,和分钟
- ⌛ 返回值: 入参对应时间的时间戳,当前实现的如果当前时间大于入参时间,将返回后一天的时间戳(ms)
function getTimestamp(hour, minute) {
const now = new Date();
const target = new Date();
target.setHours(hour);
target.setMinutes(minute);
target.setSeconds(0);
target.setMilliseconds(0);
const nowTimestamp = now.getTime();
const targetTimestamp = target.getTime();
if (nowTimestamp > targetTimestamp) {
target.setDate(target.getDate() + 1);
}
return target.getTime();
},
getTimestamp('14','34')