【发布时间】:2017-02-06 19:17:30
【问题描述】:
我的时间和日期系统适用于今天、明天和设定的日期。现在我想为系统创建某种 Console.Read 以便您可以输入任何日期并接收相应的日期。
static void date()
{
DateTime now = DateTime.Today;
Console.WriteLine("Today's date is {0}\n", now);
DateTime currTimeAndDate = DateTime.Now;
Console.WriteLine("Today's time and date is {0}\n", currTimeAndDate);
DateTime tomorrow = currTimeAndDate.AddDays(1);
Console.WriteLine("Tomorrow's date will be {0}\n", tomorrow);
DateTime then = new DateTime(1995,4,28);
Console.WriteLine("I was born {0}\n", then.DayOfWeek);
Console.Write("Press any key to continue.....\n");
Console.ReadLine();
}
static void inputDate()
{
Console.ReadLine();
}
}
}
【问题讨论】:
-
究竟是什么问题?如何输入日期时间?如果一切都失败了,输入一个字符串,然后在上面使用
Convert.ToDateTime。 -
在静态 void inputDate 中,我想从输入中获取一些东西,例如 'code' static void inputDate() { DateTime year; Console.WriteLine("|-------------------------------------------- ----------------------------------|"); year = Console.WriteLine("请使用 MM/DD/YY 格式输入日期"); Console.ReadLine(year + then.DayOfWeek) }
-
所以实现该代码,然后告诉我们它是否有效。如果没有,请说明原因以及您收到了哪些错误/异常。