我需要帮助来显示这样的东西。如果您认识,这是我们 Stack Overflow 帐户的会员期限。
member for 2 years, 3 months
我需要稍微修改一下。我的条件和显示格式如下:
Conditions Display Format
1. Below 7 days -> Days (5 days)
2. 7 -30 days -> Weeks, days ( 2 Weeks, 3 Days) in case of 17 days.
3. 30 - 365 -> Months, Weeks, Days (4Months, 2Weeks, 2Days) in case of 136 days
3. 365 or grter -> Years, Months only (2years, 3 Months)
What I did:
我正在使用 Timespan 来获取日期差异。但我对我的输出不满意。我有一个会员,其注册在 2-3 天后将 2 个月大,但仍然显示 1 个月前。这是我的代码:
TimeSpan ts = DateTime.Now - Convert.ToDateTime(company.RegistrationDate);
if (ts.Days > 365)
membersince.InnerText = string.Format("{0} years", (ts.Days / 365));
else if (ts.Days < 30)
membersince.InnerText = string.Format("{0} days", ts.Days);
else if(ts.Days > 30)
membersince.InnerText = string.Format("{0} months", (ts.Days/30));