如何使用.NET中的DatePart获取天数(星期日到星期六)?我的想法是,如果是周六或周日,我必须跳过循环。
答案 0 :(得分:3)
while (true)
{
if (DateTime.Now.DayOfWeek == DayOfWeek.Saturday
|| DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
{
break;
}
}
答案 1 :(得分:1)
因此,对于日期范围,您可以尝试:
for(var curr_date = fromDate; curr_date <= toDate; curr_date.AddDays(1))
{
if (curr_date.DayOfWeek == DayOfWeek.Saturday ||
curr_date.DayOfWeek == DayOfWeek.Sunday)
{
break;
}
}
答案 2 :(得分:0)
string s = DateTime.Now.DayOfWeek.ToString();
if (s == "Saturday")
{
//Your code
}
您可以添加适合应用程序的条件