var s1 = "2015-3-10" ; //妈妈钱包上线时间
var s2 = nowDate; //今天的时间
var totalDays = DateDiff(s1,s2); //日期相减所得天数
//计算天数差的函数,通用
function DateDiff(sDate1, sDate2){ //sDate1和sDate2是2002-12-18格式
var aDate, oDate1, oDate2, iDays;
aDate = sDate1.split("-") ;
oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) ; //转换为12-18-2002格式
aDate = sDate2.split("-") ;
oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) ;
iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24); //把相差的毫秒数转换为天数
return iDays;
}
//显示时间函数
function displayTime(){
$('p span').text(years);
$('p em').text(remainDays);
setInterval(function(){
$('p span').text(years);
$('p em').text(remainDays);
remainDays++;
},3000)
}
if (731 < totalDays <= 1096) {
var years = 2;
var remainDays = totalDays - 731;
displayTime();
}else if(totalDays > 1096){
var years = 3;
var remainDays = totalDays - 1096;
displayTime();
}