DateTime Time = DateTime.Now;
string format = "ddd";
Console.WriteLine(Time.ToString(format));
if (Time = "Mon; Tue; Wed; Thu; Fri;")
{
Console.WriteLine("It is a week day");
}
else
{
Console.WriteLine("it is a weekend");
}
我试图让这段代码检查日期并根据当天显示回复。很抱歉,如果这是一个简单的问题,但我不熟悉编码,我无法在任何地方找到解决方案
答案 0 :(得分:3)
你可以这样做。
bool isWeekDay == DateTime.Today.DayOfWeek > DayOfWeek.Sunday
&& DateTime.Today.DayOfWeek < DayOfWeek.Saturday;
if (isWeekDay) {
Console.WriteLine("It is a week day");
}
else {
Console.WriteLine("it is a weekend");
}
答案 1 :(得分:-3)
试
DateTime Time = DateTime.Now;
string format = "ddd";
Console.WriteLine(Time.ToString(format));
string day = Time.ToString(format);
if (day = "Mon; Tue; Wed; Thu; Fri;")
{
Console.WriteLine("It is a week day");
}
else
{
Console.WriteLine("it is a weekend");
}