-
js根据生日计算出年龄
- /*根据出生日期算出年龄*/
- function jsGetAge(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.getFullYear();
- 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;//返回周岁年龄
-
- }
-
相关阅读:
Python有用的内置函数divmod,id,sorted,enumerate,input,oct,eval,exec,isinstance,ord,chr,filter,vars,zip
audio的自动播放报错解决
高德搜索定位,获取信息
柱状图的点击事件
高德局部刷新标记点,bug解决
递归
CentOS7搭建LNMP环境
CentOS7安装RabbitMQ
前端项目代码加密教程
复杂度分析
-
原文地址:https://www.cnblogs.com/zqyanywn/p/5978069.html
Copyright © 2020-2023
润新知