C# 除了未来,如何设定日期?
我正在写一个程序,用户必须输入一个日期。我的问题是:C# 除了未来,如何设定日期?,c#,C#,我正在写一个程序,用户必须输入一个日期。我的问题是: 如何将日期设置为今天和过去,而不是未来 如何将日期设置为非US格式,即dd/mm/yyyy,以便编译器将中间值读取为月 这就是我的代码的样子: static DateTime date; 像这样的方法 public static void EnterDates() { for (int i = 0; i < days; i++) { Console.Write("Enter the date (dd/
static DateTime date;
像这样的方法
public static void EnterDates()
{
for (int i = 0; i < days; i++)
{
Console.Write("Enter the date (dd/mm/yyyy): ");
date = DateTime.Parse(Console.ReadLine());
centers[k].dates[i] = date;
Console.WriteLine("Day " + centers[k].dates[i]);
Console.Write("Number of movie screenings: ");
movieScreen = Convert.ToInt32(Console.ReadLine());
centers[k].movieScreen[i] = movieScreen;
Console.Write("Total number of customers: ");
customers = Convert.ToInt32(Console.ReadLine());
centers[k].customers[i] = customers;
centers[k].revenue[i] = movieScreen * customers * (centers[k].Price * 1.13);
centers[k].totalRevenue += centers[k].revenue[i];
public静态无效EnterDates()
{
对于(int i=0;i
如何将日期设置为今天和过去,而不是未来
根据您当前拥有的数据,您可以在用户输入日期后添加验证,并将其与日期时间进行比较。现在
if(date < DateTime.Now)
//valid
else
//invalid
date = DateTime.ParseExact(Console.ReadLine(), "dd/MM/yyyy", CultureInfo.InvariantCulture)