DateTime获得年龄

2014-12-31 16:07:49  访问(1493) 赞(0) 踩(0)


        /// <summary>
        /// DateTime获得年龄
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="dtNow"></param>
        /// <returns></returns>
        public int DateTimeGetAge(DateTime dtBorn, DateTime dtNow)
        {
            int year = dtNow.Year - dtBorn.Year;

            int theResult = 0;

            if (dtBorn.AddYears(year) > dtNow)
                theResult = year - 1;
            else
                theResult = year;

            return theResult;
        }


标签:DateTime获得年龄 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)