zoukankan      html  css  js  c++  java
  • 周岁算法

    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.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;//返回周岁年龄

    }

  • 相关阅读:
    赛孚耐(SafeNet)加密狗 C#调用代码
    转 RMAN-20033
    MyBatis <foreach>
    MySQL InnoDB锁问题
    MySQL MyISAM表锁
    MySQL锁概述
    MySQL 优化表数据类型
    MySQL 优化分页思路
    MySQL EXPLAIN
    MySQL 开启慢查询日志
  • 原文地址:https://www.cnblogs.com/wcLT/p/9442577.html
Copyright © 2011-2022 走看看