js 判断日期时间差
生活随笔
收集整理的這篇文章主要介紹了
js 判断日期时间差
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
alert(GetDateDiff("2018-02-27 19:20:22","2018-02-27 09:20:22","hour"));function GetDateDiff(startTime, endTime, diffType) {//將xxxx-xx-xx的時(shí)間格式,轉(zhuǎn)換為 xxxx/xx/xx的格式 startTime = startTime.replace(/\-/g, "/");endTime = endTime.replace(/\-/g, "/");//將計(jì)算間隔類性字符轉(zhuǎn)換為小寫diffType = diffType.toLowerCase();var sTime =new Date(startTime); //開(kāi)始時(shí)間var eTime =new Date(endTime); //結(jié)束時(shí)間//作為除數(shù)的數(shù)字var timeType =1;switch (diffType) {case"second":timeType =1000;break;case"minute":timeType =1000*60;break;case"hour":timeType =1000*3600;break;case"day":timeType =1000*3600*24;break;default:break;}return parseInt((eTime.getTime() - sTime.getTime()) / parseInt(timeType)); }轉(zhuǎn)載于:https://my.oschina.net/hehongbo/blog/1627110
總結(jié)
以上是生活随笔為你收集整理的js 判断日期时间差的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Gram matrix 格拉姆矩阵
- 下一篇: eclipse init 配置