当前位置:网站首页>计算时间差
计算时间差
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;
}
边栏推荐
- 渗透测试 ( 1 ) --- 必备 工具、导航
- socket通讯
- 【练习-1】(Uva 673) Parentheses Balance/平衡的括号 (栈stack)
- Write web games in C language
- Common configuration files of SSM framework
- 【练习-6】(Uva 725)Division(除法)== 暴力
- The "sneaky" new asteroid will pass the earth safely this week: how to watch it
- Penetration test (4) -- detailed explanation of meterpreter command
- QT实现窗口渐变消失QPropertyAnimation+进度条
- (POJ - 3258) River hopper (two points)
猜你喜欢
628. Maximum product of three numbers
The concept of C language array
window11 conda安装pytorch过程中遇到的一些问题
QT实现窗口置顶、置顶状态切换、多窗口置顶优先关系
渗透测试 ( 5 ) --- 扫描之王 nmap、渗透测试工具实战技巧合集
【高老师UML软件建模基础】20级云班课习题答案合集
“鬼鬼祟祟的”新小行星将在本周安全掠过地球:如何观看
Maximum product (greedy)
【练习-4】(Uva 11988)Broken Keyboard(破损的键盘) ==(链表)
Penetration test (1) -- necessary tools, navigation
随机推荐
[exercise-1] (UVA 673) parentheses balance/ balanced brackets (stack)
Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
分享一个在树莓派运行dash应用的实例。
1605. Sum the feasible matrix for a given row and column
图图的学习笔记-进程
快速转 TypeScript 指南
Share an example of running dash application in raspberry pie.
Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures
[analysis of teacher Gao's software needs] collection of exercises and answers for level 20 cloud class
Flask框架配置loguru日志庫
渗透测试 ( 1 ) --- 必备 工具、导航
Nodejs+vue online fresh flower shop sales information system express+mysql
QNetworkAccessManager实现ftp功能总结
1855. Maximum distance of subscript alignment
Quick to typescript Guide
B - Code Party (girls' competition)
Penetration test (1) -- necessary tools, navigation
[exercise-2] (UVA 712) s-trees
1013. Divide the array into three parts equal to and
【练习-2】(Uva 712) S-Trees (S树)