|
|
@@ -60,5 +60,27 @@ namespace TelpoPush.Ability.Worker.Common |
|
|
|
return dt.ToString("yyyy-MM-dd"); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 计算年龄 |
|
|
|
/// </summary> |
|
|
|
/// <param name="birthday">出生日期(生日)</param> |
|
|
|
/// <param name="isYear">年:true(年);false(月,天)</param> |
|
|
|
/// <returns></returns> |
|
|
|
public static int GetAge(DateTime birthday,bool isYear=false) { |
|
|
|
|
|
|
|
DateTime today = DateTime.Today; |
|
|
|
if (today < birthday) |
|
|
|
return 0; |
|
|
|
|
|
|
|
// 计算年龄 |
|
|
|
int age = today.Year - birthday.Year; |
|
|
|
if (!isYear) |
|
|
|
{ |
|
|
|
// 如果今天日期还没到生日日期,则年龄减一 |
|
|
|
if (today.Month < birthday.Month || (today.Month == birthday.Month && today.Day < birthday.Day)) |
|
|
|
age--; |
|
|
|
} |
|
|
|
return age; |
|
|
|
} |
|
|
|
} |
|
|
|
} |