C#精确判断一个人的年龄

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication1
{
    class Program
    {
        public static string GetAge(DateTime dtBirthday)
        {
            string strAge = string.Empty;       
            int intYear = 0;                                   
            int intMonth = 0;                                   
            int intDay = 0;                                  

            DateTime dtNow = DateTime.Now;
    
            intDay = dtNow.Day - dtBirthday.Day;
            if (intDay < 0)
            {
                dtNow = dtNow.AddMonths(-1);
                intDay += DateTime.DaysInMonth(dtNow.Year, dtNow.Month);
            }

            intMonth = dtNow.Month - dtBirthday.Month;
            if (intMonth < 0)
            {
                intMonth += 12;
                dtNow = dtNow.AddYears(-1);
            }

            intYear = dtNow.Year - dtBirthda

你可能感兴趣的:(《VS/C/C++/C#》)