javascript比較兩個日期之間相隔天數
$(function () {
var starttime = transdate("2014-09-30 15:53:00");
var endtime = transdate("2014-10-03 15:53:00");
var now = "'"+new Date().getTime()+"'";
var nowtime = now.substr(1,10);
if(nowtime > endtime){
$('.meeting_time').html('展會已結束');
}else if(nowtime < starttime){
var day = get_date_different(nowtime,starttime);
$('.meeting_time').html('距展會開始還有'+day+'天');
}else{
$('.meeting_time').html('展會進行中');
}
});
function get_(www.111cn.net)date_different(date_1,date_2){
var days= date_2 - date_1;
var time = parseInt(days / (60 * 60 * 24));
return time;
}
function transdate(endTime){
var date=new Date();
date.setFullYear(endTime.substring(0,4));
date.setMonth(endTime.substring(5,7)-1);
date.setDate(endTime.substring(8,10));
date.setHours(endTime.substring(11,13));
date.setMinutes(endTime.substring(14,16));
date.setSeconds(endTime.substring(17,19));
return Date.parse(date)/1000;
}from:http://www.111cn.net/wy/js-ajax/66437.htm