具体使用根据情况大家自己调整,此处仅供参考。
------------------------------根据出生日期计算生日天数-----------------------------
jxCore.BirthWarm = function(value, fieldCtl){
var Birth="";
var ksRows="";
var now = new Date();
var tY=0;
var tM=0;
var tD=0;
ksRows = fieldCtl.rowControl.rowData();
Birth = ksRows["出生日期"];
if(value == null)
{
value = "暂缺出生日期";
return value;
}
var dd = eval('new ' + Birth.substr(1, Birth.length - 2));
var ar_date = [dd.getMonth() + 1,dd.getDate() ,dd.getFullYear()];
tY =now.getFullYear();
tM = now.getMonth()+1;
tD = now.getDate();
var params = new Array(tY,tM,tD,ar_date);
var diffDay = jxCore.getdiffDay(params);
value = diffDay;
return value;
};
//此处供方法:jxCore.BirthWarm服务
jxCore.getdiffDay = function(params){
var arry_nonleapyear = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
var arry_leapyear = new Array(0,31,29,31,30,31,30,31,31,30,31,30,31);
var tY = params[0];
var tM = params[1];
var tD = params[2];
var array =params[3];
var m = array[0];
var d = array[1];
var y = array[2];
var diff_days1=0;
var diff_days2=0;
var sum=0;
//闰年生日天数计算
if((tY % 4==0) && (tY % 100!=0) || ( tY % 400==0 ))
{
if(tM > m)
{
//计算当月剩余天数
diff_days1=arry_leapyear[tM] - tD;
//计算当生日月剩余天数
diff_days2 = d;
var up = 0;
var down = 0;
for(var i =1;i < m;i++)
{
up = up + arry_leapyear[i];
}
for(;tM < arry_leapyear.length;tM++)
{
down = down + arry_leapyear[tM+1];
}
sum = up + down + diff_days1 + diff_days2;
}
else
{
//计算当前月剩余天数
diff_days1 = arry_leapyear[tM] - tD;
//计算当生日月剩余天数
diff_days2 = d;
if(tM == m) //生日月等于当前月
{
if(tD > d)
{
sum = 366+d-tD;
}
else
{
sum = d-tD;
}
}
else//生日月大于当前月
{
for( ;tM < m-1;tM++)
{
sum = sum + arry_leapyear[tM+1];
}
sum = sum + diff_days1 + diff_days2;
}
}
return sum;
}
//平年生日天数计算
else
{
if(tM > m)//生日月小于当前月
{
//计算当月剩余天数
diff_days1 = arry_nonleapyear[tM] - tD;
//计算当生日月剩余天数
diff_days2 = d;
var up = 0;
var down = 0;
for(var i =1;i < m;i++)
{
up = up + arry_nonleapyear[i];
}
for(;tM < arry_nonleapyear.length;tM++)
{
down = down + arry_nonleapyear[tM+1];
}
sum = up + down + diff_days1 + diff_days2;
}
else
{
//计算当前月剩余天数
diff_days1 = arry_nonleapyear[tM] - tD;
//计算当生日月剩余天数
diff_days2 = d;
if(tM == m) //生日月等于当前月
{
if(tD > d)
{
sum = 365+d-tD;
}
else
{
sum = d-tD;
}
}
else//生日月大于当前月
{
for( ;tM < m-1;tM++)
{
sum = sum + arry_nonleapyear[tM+1];
}
sum = sum + diff_days1 + diff_days2;
}
}
return sum;
}
};
转载于:https://www.cnblogs.com/L-Blews/p/6483861.html