jquery判断两个日期之间相差多少天/小时

Jquery 判断相差多少天
<script>
function diy_time(time1,time2){
    time1 = Date.parse(new Date(time1));
    time2 = Date.parse(new Date(time2));
    return time3 = '相差'+Math.abs(parseInt((time2 - time1)/1000/3600/24))+'天';
}
var time1 = "2014-07-10 10:21:12";
var time2 = "2014-07-9 10:21:00";
alert(diy_time(time1,time2));
</script>
Jquery 判断相差多少小时
<script>
function diy_time(time1,time2){
    time1 = Date.parse(new Date(time1));
    time2 = Date.parse(new Date(time2));
    return time3 = '相差'+Math.abs(parseInt((time2 - time1)/1000/3600))+'小时';
}
var time1 = "2014-07-10 10:21:12";
var time2 = "2014-07-9 10:21:00";
alert(diy_time(time1,time2));
</script>

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

使用新浪微博登陆