当前位置:网站首页>计算时间差
计算时间差
2022-07-06 09:28:00 【梦想身高1米8】
// deadline:string 截止日期
// 计算当前之间到截止日期还有多久
// return:string x天x小时x分x秒
const computeRemainTime = deadlineTime => {
let r = '';
// 截止日期和当前时间之间相差多少毫秒
let seconds = new Date(deadlineTime).getTime() - new Date().getTime();
// 相差天数
const day = Math.floor(seconds / (24 * 3600 * 1000));
r += day ? day + '天' : '';
// 去掉天数的毫秒数
seconds = seconds % (24 * 3600 * 1000);
// 还剩几个小时
const hour = Math.floor(seconds / (3600 * 1000));
r += hour ? hour + '小时' : '';
// 去掉小时的毫秒数
seconds = seconds % (3600 * 1000);
// 还剩几分钟
const minute = Math.floor(seconds / (60 * 1000));
r += minute ? minute + '分' : '';
// 还剩几秒钟
seconds = seconds % (60 * 1000);
// 去掉分钟的毫秒数
const second = Math.round(seconds / 1000);
r += second ? second + '秒' : '';
return r;
}
边栏推荐
猜你喜欢
1689. Ten - the minimum number of binary numbers
QWidget代码设置样式表探讨
Information security - threat detection engine - common rule engine base performance comparison
Penetration test (1) -- necessary tools, navigation
TCP's three handshakes and four waves
MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’
信息安全-史诗级漏洞Log4j的漏洞机理和防范措施
Penetration test (8) -- official document of burp Suite Pro
QT有关QCobobox控件的样式设置(圆角、下拉框,向上展开、可编辑、内部布局等)
Some problems encountered in installing pytorch in windows11 CONDA
随机推荐
【练习-8】(Uva 246)10-20-30==模拟
2027. Minimum number of operations to convert strings
X-forwarded-for details, how to get the client IP
Gartner:关于零信任网络访问最佳实践的五个建议
Ball Dropping
1529. Minimum number of suffix flips
Suffix expression (greed + thinking)
(POJ - 3579) median (two points)
[exercise-7] crossover answers
双向链表—全部操作
Basic Q & A of introductory C language
807. Maintain the urban skyline
Flag framework configures loguru logstore
Sanic异步框架真的这么强吗?实践中找真理
Flask框架配置loguru日志库
b站 實時彈幕和曆史彈幕 Protobuf 格式解析
F - birthday cake (Shandong race)
MySQL授予用户指定内容的操作权限
Pyside6 signal, slot
【练习-5】(Uva 839)Not so Mobile(天平)