当前位置:网站首页>计算时间差
计算时间差
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;
}
边栏推荐
- 读取和保存zarr文件
- Perform general operations on iptables
- [exercise 4-1] cake distribution
- X-forwarded-for details, how to get the client IP
- Candy delivery (Mathematics)
- Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures
- Is the sanic asynchronous framework really so strong? Find truth in practice
- Basic Q & A of introductory C language
- Socket communication
- 【练习-8】(Uva 246)10-20-30==模拟
猜你喜欢

Penetration test (4) -- detailed explanation of meterpreter command

QT按钮点击切换QLineEdit焦点(含代码)

Vs2019 initial use

Flask框架配置loguru日志库
Frida hook so layer, protobuf data analysis

Essai de pénétration (1) - - outils nécessaires, navigation

C language is the watershed between low-level and high-level

Some problems encountered in installing pytorch in windows11 CONDA

Information security - Analysis of security orchestration automation and response (soar) technology

Penetration test (7) -- vulnerability scanning tool Nessus
随机推荐
Opencv learning log 27 -- chip positioning
Maximum product (greedy)
Penetration test 2 --- XSS, CSRF, file upload, file inclusion, deserialization vulnerability
409. Longest palindrome
1855. Maximum distance of subscript alignment
Data storage in memory & loading into memory to make the program run
Opencv learning log 28 -- detect the red cup cover
[exercise-7] (UVA 10976) fractions again?! (fraction split)
树莓派CSI/USB摄像头使用mjpg实现网页摄像头监控
Sanic异步框架真的这么强吗?实践中找真理
第 300 场周赛 - 力扣(LeetCode)
Flask框架配置loguru日志庫
Openwrt source code generation image
Gartner:关于零信任网络访问最佳实践的五个建议
window11 conda安装pytorch过程中遇到的一些问题
最全编程语言在线 API 文档
Nodejs+vue online fresh flower shop sales information system express+mysql
树莓派4B安装opencv3.4.0
栈的经典应用—括号匹配问题
860. Lemonade change