JS中根據身份證號獲取年齡 出生日期

2022-07-11 19:30:11 字數 728 閱讀 7269

//獲取年齡

function getage(身份證號)

if (len == 15)//15位身份證號

//時間字串裡,必須是「/」隔開

var birthdate = new date(strbirthday);

var nowdatetime = new date();

var age = nowdatetime.getfullyear() - birthdate.getfullyear();

//月、天的因素;.getmonth()獲取的是從0開始

if (nowdatetime.getmonth() < birthdate.getmonth() || (nowdatetime.getmonth() == birthdate.getmonth() && nowdatetime.getdate() < birthdate.getdate()))

return age;

}//獲取出生日期

//18位身份證號

var birthday=身份證號.substr(6, 4) + "-" +身份證號.substr(10, 2) + "-" + 身份證號.substr(12, 2);

//15位身份證號

var birthday = "19" + 身份證號.substr(6, 2) + "/" + 身份證號.substr(8, 2) + "/" + 身份證號.substr(10, 2);

mysql根據身份證號計算年齡

身份證號包含著出生日期,我們可以通過身份證號與當前日期來計算人的年齡。現有資料表 計算規則為先取出年份與當前年份作差,再比較當前日期與身份證上的月日 即判斷此人是否已經過了國曆生日 決定是否需要減去一歲,已經過了生日就不用減掉了。計算年齡的sql如下 an highlighted block sel...

通過身份證號計算年齡

sfzhm 計算年齡複製 var sfzhm document.getelementbyid sfzhm value if sfzhm.length 15 var date1 new date 取得當前日期 var year1 date1.getfullyear 取得當前年份 var month1 ...

根據身份證號生成出生日期

修改者 lics 說明 根據身份證號生成出生日期 package nc.ui.ps.pub import nc.vo.pub.busines ception import nc.vo.pub.lang.ufdate import nc.vo.uap.busibean.exception.busibe...