對于每個月,注冊用戶使用 C# 和 ASP NET 編制與上個月相關的客戶滿意度調查。
例如:
本月6月,必須完成上月5月的客戶滿意度調查。
5 月份的調查必須在 6 月 1 日至 6 月 15 日期間完成。
從 6 月 16 日到 6 月 30 日,我需要顯示一個警報,即 6 月份的調查將從 7 月 1 日開始提供。
這段 C# 代碼對您來說是否正確?
string tMonthS = DateTime.Now.AddMonths(1).ToString("MMMM");
DateTime dt = DateTime.Now;
DateTime start = new DateTime(dt.Year, dt.Month, 1).AddDays(15);
DateTime end = start.AddMonths(1).AddDays(-16);
string startOfMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1).ToString("dd/MM/yyyy");
if (dt == start && dt <= end)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Msg",
"alert('Alert! The survey for the month of " tMonthS.ToString() " " DateTime.Now.Year "\\n"
"available from the day " startOfMonth.ToString() "');", true);
}
uj5u.com熱心網友回復:
你可能想要dt >= start在你的條件中,因為否則它只會匹配一天(也在那天早上的午夜),你也不想對這個end值做減法,因為這不是在所有月份都可用;您應該能夠從或類似end的計算鏈中獲得。start.GetMonth().AddMonths(1)我不建議將它實際編碼在這樣的一行中,但這是我認為的想法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/487063.html
