我是靠谱客的博主 怡然蜜粉,这篇文章主要介绍编写函数,要求传入两个时间节点,能返回两个时间节点之间相差 多少天多少小时多少分钟多少秒编写函数,要求传入两个时间节点,能返回两个时间节点之间相差 多少天多少小时多少分钟多少秒,现在分享给大家,希望可以做个参考。

编写函数,要求传入两个时间节点,能返回两个时间节点之间相差 多少天多少小时多少分钟多少秒

function fn(a, b) {
time1 = new Date(a)
time2 = new Date(b)
var cha = Math.abs(parseInt((time1.getTime() - time2.getTime()) / 1000))
//秒,时间差
var day = parseInt(cha / (60 * 60 * 24))
//天
var hour = parseInt((cha - day * (60 * 60 * 24)) / 60 / 60)
//小时
var minute = parseInt((cha / 60) % 60)
//相差的分
var second = cha % 60
//秒
return "两个时间节点之间相差" + day + "天" + hour + "个小时" + minute + "分钟" + second + "秒"
}
console.log(fn("2010-08-12 17:35:52", "2011-11-18 05:10:12"));
// 两个时间节点之间相差462天11个小时34分钟20秒

最后

以上就是怡然蜜粉最近收集整理的关于编写函数,要求传入两个时间节点,能返回两个时间节点之间相差 多少天多少小时多少分钟多少秒编写函数,要求传入两个时间节点,能返回两个时间节点之间相差 多少天多少小时多少分钟多少秒的全部内容,更多相关编写函数,要求传入两个时间节点,能返回两个时间节点之间相差内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(123)

评论列表共有 0 条评论

立即
投稿
返回
顶部