1.根据日期计算年龄
public int GetAgeByBirthdate(DateTime birthdate,DateTime? Date)
{
DateTime dt = DateTime.Parse(Date.ToString());//传过来的日期
DateTime now = DateTime.Now;//当前日期
int age = dt.Year - birthdate.Year;
if (dt.Month < birthdate.Month || (dt.Month == birthdate.Month && dt.Day < birthdate.Day))
{
age--;
}
return age < 0 ? 0 : age;
}
2.数字转化
public string ToNum(string x)
{
switch (x)
{
case "1": return "一";
case "2": return "二";
case "3": return "三";
case "4": return "四";
default: return "零";
}
}