출생일에 따라 나이를 계산하다

1435 단어 날짜
//   YYYY-MM-dd
		function getAge(strBirthday){       
    		var returnAge;
   			var strBirthdayArr=strBirthday.split("-");
    		var birthYear = strBirthdayArr[0];
    		var birthMonth = strBirthdayArr[1];
    		var birthDay = strBirthdayArr[2];
    
    		d = new Date();
    		var nowYear = d.getYear();
    		var nowMonth = d.getMonth() + 1;
    		var nowDay = d.getDate();
    
    		if(nowYear == birthYear){
        		returnAge = 0;//   0 
    		} else {
        		var ageDiff = nowYear - birthYear ; // 
        		if(ageDiff > 0){
            		if(nowMonth == birthMonth){
                		var dayDiff = nowDay - birthDay;// 
                		if(dayDiff < 0){
                    		returnAge = ageDiff - 1;
                		} else {
                    		returnAge = ageDiff ;
                		}
            		} else {
                		var monthDiff = nowMonth - birthMonth;// 
                		if(monthDiff < 0) {
                    		returnAge = ageDiff - 1;
                		} else {
                    		returnAge = ageDiff ;
                		}
            		}
       			} else {
            		returnAge = -1;// -1    
        		}
    		}
    		return returnAge;// 
		}

좋은 웹페이지 즐겨찾기