關於年齡周歲的精確計算邏輯
using system;
using system.collections.generic;
using system.linq;
using system.text;
else
int num2 = datetime.day - birthday.value.day;
bool flag3 = num2 <0;
if(flag3)
int num3 = datetime.month - birthday.value.month;
bool flag4 = num3 <0;
if(flag4)
int num4 = datetime.year - birthday.value.year;
bool flag5 = num4 >=1;
//如果當前2023年比2019生日大於等於1,就有年,否則不足整年不帶年
if(flag5)
歲", num4);}
int g_cshowmonth = pubconfig.g_cshowmonth;
//我們配置5歲,小於此歲數,顯示月
bool flag6 = num3 >
0&& num4 <= g_cshowmonth;
//大於0月,年歲<=5歲
if(flag6)
個月", num3);}
int g_cshowday = pubconfig.g_cshowday;
//我們配置6天
bool flag7 = num2 >=
0&& num4 <= g_cshowmonth && num3 <= g_cshowday;
//大於0天,小於等於5歲,小於等於6天,顯示天
if(flag7)
天", num2);}
int g_cshowhour = pubconfig.g_cshowhour;
//我們配置10小時,
bool flag8 = num >
0&& num4 <= g_cshowmonth && num3 <= g_cshowday && num2 <= g_cshowhour;
//大於0小時,小於配置小時,直接顯示小時數
if(flag8)
小時", num);}
result = stringbuilder.
tostring()
;//不足1小時,應該顯示0小時,
}return result;}}
public
static
class
pubconfig
}
「yyyymmdd「日期格式的lua周歲計算
侵刪 int now int.parse datetime.today.tostring yyyymmdd int dob int.parse datedob.tostring yyyymmdd string dif now dob tostring string age 0 if dif.leng...
php簡單計算年齡的方法 周歲與虛歲
本文例項講述了php簡單計算年齡的方法。分享給大家供大家參考,具體如下 date是時間戳 type為1的時候是虛歲,2的時候是周歲 function getagebybirth date,type 1 else else return age ps 本站還提供了乙個unix時間戳轉換工具,包含了各種...
Jquery計算年齡
function countage birthday var curdate new date var oridate new date timestr var curyear parseint curdate.getfullyear 返回4位完整的年份 var oriyear parseint o...